Change dialog text color on 5.0+(在 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 的主题
大多数解决方案在低于 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+ 上更改对话框文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 5.0+ 上更改对话框文本颜色


基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01