2015-02-10 49 views
7

我試圖更改對話框中的文本顏色,最常見的是AlertDialog。我已經嘗試每一個解決方案,在這些頁面:更改5.0+上的對話框文本顏色

AlertDialog styling - how to change style (color) of title, message, etc

How can I change the color of AlertDialog title and the color of the line under it

How to change theme for AlertDialog

大多數解決方案的工作低於5.0,但它上面,他們似乎沒有任何效果。我應該爲5.0+改變什麼不同的屬性?

我的應用程序的父主題是「Theme.AppCompat.Light.NoActionBar」

回答

31

在你的情況,我認爲,對話主題是可行的。

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.YourDialogStyle; 

您可以像上面的代碼一樣指定對話框主題。

<style name="YourDialogStyle" parent="Theme.AppCompat.Light.Dialog"> 
    <item name="android:colorAccent">@color/primary</item> 
    <item name="android:textColor">@color/accent</item> 
    <item name="android:textColorPrimary">@color/primary_dark</item> 
</style> 

以下是Dialog主題的示例。

  • android:colorAccent會影響您的負面或正面按鈕的文字顏色。
  • android:textColor會影響對話框的標題文字顏色。
  • android:textColorPrimary會影響對話框的消息顏色。

另一種選擇是您可以爲對話框製作自己的自定義佈局。