在5.0+以上更改对话框文本颜色 [英] Change dialog text color on 5.0+

查看:149
本文介绍了在5.0+以上更改对话框文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to change the text color in dialog boxes, most commonly AlertDialog. I've tried every solution at these pages:

AlertDialog样式 - 如何更改标题,消息等的样式(颜色)

如何更改AlertDialog标题的颜色和其下的行的颜色

如何更改AlertDialog的主题

大多数解决方案的工作原理是BELOW 5.0但在上面,它们似乎没有任何效果。 5.0+以上我应该改变哪些不同的属性?

Most solutions work BELOW 5.0 but above it, and they don't seem to have any effect. What different attributes should I be changing for 5.0+?

我的应用程序的父主题是Theme.AppCompat.Light.NoActionBar

The parent theme of my app is "Theme.AppCompat.Light.NoActionBar"

推荐答案

在你的情况下,我认为对话主题将会起作用。

In your case, I think the dialog theme would work.

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

您可以指定对话框主题,就像

You can specify your dialog theme just like the code above.

<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主题的示例。

Here is the example of theme for Dialog.


  • android:colorACCentry 将影响您的文字颜色为负面或正面的按钮。

  • android:textC olor 会影响对话框的标题文字颜色。

  • android:textColorPrimary 将影响对话框的消息颜色。 b
  • android:colorAccent will affect your text colors of negative or positive buttons.
  • android:textColor will affect your title text color of dialog.
  • android:textColorPrimary will affect your message color of dialog.

另一个选项是您可以为对话框创建自己的自定义布局。

Another option is you can make your own custom layout for the dialog.

这篇关于在5.0+以上更改对话框文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆