2014-10-10 27 views
1

我正在使用以下代码来主题AlertDialogs。AlertDialog中顶部分隔符的ID

Resources resources = dialog.getContext().getResources(); 
int color = resources.getColor(R.color.green_theme); // your color here 

int alertTitleId = resources.getIdentifier("alertTitle", "id", "android"); 
TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId); 
alertTitle.setTextColor(color); // change title text color 

int titleDividerId = resources.getIdentifier("titleDivider", "id", "android"); 
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId); 
titleDivider.setBackgroundColor(color); // change divider color 

它的效果很好,除了AlertDialog带有消息但没有标题的情况。看来只有在这种情况下才会显示第三个视图,该视图也需要设置其颜色。我只是不知道这个视图的id是什么。有人知道吗?

我在说的视图在下图中的白色矩形中突出显示。

AlertDialog

回答

2

我想没有人真的看过我的问题。

不管怎么说,这里的答案,如果任何人有他的问题:

int titleDividerTopId = resources.getIdentifier("titleDividerTop", "id", "android"); 
View titleDividerTop = dialog.getWindow().getDecorView().findViewById(titleDividerTopId); 
titleDividerTop.setBackgroundColor(color); 
0
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

这应该摆脱的称号。

+0

我不想摆脱它,我想改变颜色,这样它的文本匹配。 – zholmes1 2014-10-10 06:15:14

+1

AFAIK,这是你正在使用的主题的一部分。你必须调整主题。这是一个SO帖子:http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog – 2014-10-10 06:18:28

0

做一两件事,只是改变你的整个应用程序在manifest文件的application标签为透明的主题如下:

,不会显示在对话框中的蓝线。

<application 
    android:allowBackup="true" 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Translucent.NoTitleBar" >