问题描述
我正在尝试更改对话框中的文本颜色,最常见的是 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 标题的颜色及其下方线条的颜色
大多数解决方案在低于 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:colorAccent 会影响您的负面或正面按钮的文本颜色.
- android:textColor会影响你的对话框标题文字颜色.
- android:textColorPrimary 会影响对话框的消息颜色.
- 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+ 上更改对话框文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!