2015-02-10 86 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会影响对话框的消息颜色。

另一种选择是您可以为对话框制作自己的自定义布局。