更改AlertDialog的样式
当我运行此代码时,会显示警报对话框,但对话框周围有一个白色边框,而且边框有点圆。我不想要这个白色边框,我想要有 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();
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了包装器的解决方案,您可以在其中将主题(样式)设置为当前上下文中的任何内容。我将 R.style.MyTheme 设置为警报对话框的样式,并根据自己的喜好自定义了该视图。
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.
您自己回答了您的问题,但它对我不起作用,所以这是我的答案希望对需要它的每个人都有帮助:
将此样式放入 res\values\styles.xml 文件中,然后将您的活动的主题设置为你的清单。像这样:
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:
Put this style in res\values\styles.xml file and just set the theme of your activity to it in your Manifest. Like this: