2013-03-07 42 views
11

我想要樣式或更改警報對話框中標題標題的分隔線顏色。我搜索這個問題,我想很多人在尋找這個問題,但我仍然無法找到正確的解決方案。我想改變這一點。 Blue header divider如何更改警報對話框標題分隔線顏色android

+0

你試過setDivider方法?它存在於警報對話框中嗎? – Paschalis 2013-03-07 12:45:26

+0

你可以設置它.. – Janmejoy 2013-03-07 12:50:19

+0

我爲我的舊版android版本創建了服裝對話框,但對於較新的android版本,我想更改此藍色分隔線顏色。對於舊版本,我完全創建了自定義對話框。但我不想爲更高版本使用它。所以這是問題。任何方式來改變這一點。 – nilkash 2013-03-07 12:51:34

回答

0

從來源判斷,似乎這種顏色是硬編碼的。我會認爲這是一個錯誤,它應該是有風格的imho。

雖然有一個簡單的解決方法:使用setStyle(DialogFragment.STYLE_NO_TITLE, R.style.myStyle);,並寫一個簡單的線性佈局,其中第一項是您的標題。

+2

你在給setStyle應用什麼? AlertDialogs沒有這種方法(我可以看到)。如果這項工作,我會很高興地upvote你的答案。 – PeteH 2013-09-13 08:24:43

+1

我在DialogFragment的onCreate中使用它(我建議你使用對話框片段而不是片段:http://stackoverflow.com/questions/13765127/dialogfragment-advantages-over-alertdialog) – Teovald 2013-09-14 20:00:43

15

實際上,你可以通過一個非常簡單的黑客改變AlertDialog標題的顏色:

public static void brandAlertDialog(AlertDialog dialog) { 
    try { 
     Resources resources = dialog.getContext().getResources(); 
     int color = resources.getColor(...); // 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 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 
+1

這是「未來」的安全嗎? – loeschg 2014-09-04 20:45:55

+0

最安全的你可以得到我知道 – MatrixDev 2014-09-08 07:22:20

+2

不適用於我測試過的所有Android版本。 – Patrick 2015-02-26 21:00:01

4

分頻器顏色: -

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
builder.setTitle(R.string.dialog) 
    .setIcon(R.drawable.ic) 
    .setMessage(R.string.dialog_msg); 
Dialog d = builder.show(); 
int dividerId = d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null); 
View divider = d.findViewById(dividerId); 
divider.setBackgroundColor(getResources().getColor(R.color.my_color)); 
+1

這裏的關鍵是首先運行'.show()',然後訪問對話框以獲取分隔符視圖並進行更新等。我最初錯過了這個 - 試圖在顯示對話框之前進行顏色更新,並沒有工作。簡潔的例子 - 謝謝 – gnB 2017-12-12 21:04:02

-1
QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context). 
     setTitle("Set IP Address"). 
     setTitleColor("#FF00FF"). 
     setDividerColor("#FF00FF"). 
     setMessage("You are now entering the 10th dimension."). 
qustomDialogBuilder.show(); 
相關問題