Change dialog text color on 5.0+

我的梦境 提交于 2019-12-19 02:27:26

问题


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

AlertDialog styling - how to change style (color) of title, message, etc

How can I change the color of AlertDialog title and the color of the line under it

How to change theme for AlertDialog

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+?

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


回答1:


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>

Here is the example of theme for Dialog.

  • 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.



来源:https://stackoverflow.com/questions/28438673/change-dialog-text-color-on-5-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!