更改AlertDialog的样式

发布于 2024-12-13 17:37:05 字数 967 浏览 2 评论 0原文

当我运行此代码时,会显示警报对话框,但对话框周围有一个白色边框,而且边框有点圆。我不想要这个白色边框,我想要有 90 度角的真实角。我希望你明白我想要做什么。

        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        Button bbb=new Button(MvcnContactList.this);
        ad.setView(bbb);
        alertDialog = ad.create();
        alertDialog.show();

在此处输入图像描述

有没有办法设置警报对话框的样式,但不能设置文本颜色或文本大小或类似的内容。我想设置警报对话框的边框样式,因此仅设置一个主题也许可以解决此问题。但我不知道要覆盖哪些属性。

谢谢,

编辑: 例如,此样式将 textColor 覆盖为 00FF00 ,这很酷,但是我应该覆盖哪个属性以使角不圆,并删除那个白色的无聊者

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AlertDialogCustom" parent="@android:style/AlertDialog">
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
        <item name="android:textSize">10sp</item>
    </style>
</resources>

When I run this code the alert dialog is shown but there is one white border around the dialog and also the borders are little round. I do not want this white border and I want to have real corners with angle of 90. I hope you understand what I am trying to do.

        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        Button bbb=new Button(MvcnContactList.this);
        ad.setView(bbb);
        alertDialog = ad.create();
        alertDialog.show();

enter image description here

Is there any way to style the alert dialog but not the text color or text size or something similar... I want to style the borders of the alert dialog, so setting just a theme maybe it is solution to this problem. But I do not know what properties to override.

Thanks,

EDIT:
For example this style override the textColor to 00FF00 , and that is cool, but which property should I override to make the corners not round and tho remove that white boreder

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AlertDialogCustom" parent="@android:style/AlertDialog">
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
        <item name="android:textSize">10sp</item>
    </style>
</resources>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昨迟人 2024-12-20 17:37:05

我找到了包装器的解决方案,您可以在其中将主题(样式)设置为当前上下文中的任何内容。我将 R.style.MyTheme 设置为警报对话框的样式,并根据自己的喜好自定义了该视图。

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.MyTheme );
        AlertDialog.Builder builder= new AlertDialog.Builder( ctw );

I found solution with the wrapper, where you can set a theme (style) to anything in the current context. I set R.style.MyTheme as style to my alert dialog and I customized that view to my own taste.

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.MyTheme );
        AlertDialog.Builder builder= new AlertDialog.Builder( ctw );
等风来 2024-12-20 17:37:05

您自己回答了您的问题,但它对我不起作用,所以这是我的答案希望对需要它的每个人都有帮助:

<style name="PauseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>

</style>

将此样式放入 res\values\styles.xml 文件中,然后将您的活动的主题设置为你的清单。像这样:

android:theme="@style/PauseDialog" 

You answered your question yourself but it did not work for me, so here's my answer hope to be helpful for everyone who need it:

<style name="PauseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>

</style>

Put this style in res\values\styles.xml file and just set the theme of your activity to it in your Manifest. Like this:

android:theme="@style/PauseDialog" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文