2011-11-04 79 views
5

当我运行此代码时,将显示警告对话框,但对话框周围有一个白色边框,边框也很小。我不想要这个白色的边框,我想要90度角的真实角落。我希望你明白我想要做的事情。更改AlertDialog的样式

 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

有没有......我想样式的警告对话框中的边界,所以设置只是一个没有办法样式警告对话框不显示文本的颜色或文本大小或类似的东西主题也许是解决这个问题的方法。但我不知道要覆盖哪些属性。

感谢,

编辑: 例如这种风格覆盖文字颜色以00FF00,这是很酷,但其性质我应该重写,使边角不圆和寿去除白色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> 
+1

也许这可以帮助你: http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – rockeye

+0

这是很好的链接,但我不覆盖边界的属性... – Lukap

回答

15

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

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

但是,为了去除圆角和边框,您在主题中覆盖了哪些属性?我有同样的问题.. – 2012-10-05 21:19:04

+0

可以请你解释/提供代码示例,了解如何删除白色边框? –

1

你自己回答了你的问题,但它并没有为我工作,所以这里是我的回答希望对大家谁需要它的帮助:

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

</style> 

将这个风格在res \值\风格.xml文件,并将您的活动主题设置在您的Manifest中。就像这样:

android:theme="@style/PauseDialog"