2014-10-10 59 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" >