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+ 上更改对话框文本颜色
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
