在5.0+上更改对话框文本颜色

时间:2015-02-10 18:05:44

标签: android dialog

我试图更改对话框中的文本颜色,最常见的是AlertDialog。我在这些页面上尝试了所有解决方案:

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"

1 个答案:

答案 0 :(得分:32)

在您的情况下,我认为对话框主题可行。

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

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

相关问题