更改AlertDialog的样式 [英] Change the style of AlertDialog

查看:236
本文介绍了更改AlertDialog的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行此代码时,将显示警告对话框,但对话框周围有一个白色边框,边框也很圆。我不想要这个白色边框,我想要有角度为90°的真正的角落。我希望你明白我想做什么。

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.

感谢,

编辑:
例如这种风格覆盖textColor为00FF00,这是很酷,但哪个属性应该覆盖,使角不圆,并删除白色的钻石

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>


推荐答案

我找到了包装器的解决方案,一个主题(风格)到当前上下文中的任何东西。我将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.

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

这篇关于更改AlertDialog的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆