在5.0及以上版本中更改对话框文本颜色

7
我正在尝试更改对话框中文本的颜色,最常见的是AlertDialog。我已经尝试了这些页面上的所有解决方案:AlertDialog styling - how to change style (color) of title, message, etcHow can I change the color of AlertDialog title and the color of the line under itHow to change theme for AlertDialog。大多数解决方案适用于5.0以下版本,但在5.0以上版本中,它们似乎没有任何效果。我应该更改哪些不同的属性以支持5.0+?我的应用程序的父主题是“Theme.AppCompat.Light.NoActionBar”。
1个回答

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接