android - 如何更改 Material AlertDialog 和 ProgressDialog 的微调器、文本和按钮颜色

标签 android themes

我的应用程序扩展了 Theme.AppCompat.Light, Material 风格的对话框显示为白色背景、黑色文本颜色和绿色按钮(ProgessDialog 中的微调器也是绿色的).

我想更改文本的颜色和字体,以及按钮和微调器的颜色。

我该怎么做?

我找到了 this发布但 XML 解决方案对我不起作用,其他答案是没有 ProgressDialog 的第三方库。

谢谢!

最佳答案

要获得完整的“ Material 体验”,您应该在任何地方都使用最新的 AppCompat。而不是 android.app.AlertDialog 使用 android.support.v7.app.AlertDialog 来定位设备 < 21。

只需像下面这样正确设置您的 AppTheme 就足够了:

<style name="AppTheme" parent="Base.AppTheme">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>

    <!-- This is the interesting part -->
    <item name="android:dialogTheme">@style/AppTheme.Dialog</item>
    <item name="dialogTheme">@style/AppTheme.Dialog</item>
    <item name="android:alertDialogTheme">@style/AppTheme.Dialog</item>
    <item name="alertDialogTheme">@style/AppTheme.Dialog</item>
</style>

<!-- Style the dialog like the normal AppTheme -->
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>

关于android - 如何更改 Material AlertDialog 和 ProgressDialog 的微调器、文本和按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27052981/

相关文章:

Android Studio 汽车 API

android - 自定义对话框背景图片在android中显示不清晰

ExtJs 海王星主题

android - 如何在代码中为整个应用程序设置主题,而不是在 list 中?

jquery-ui - 如何升级自定义 jQuery UI 主题?

android - 如何手动将库添加到react-native项目中?

android - 如何在不解压缩的情况下从apk文件中删除目录?

android - 使用 MediaRecorder 录制 4K

android - Material Components 主题的描述?

css - 导入 Start Bootstrap 主题