应用 ThemeOverlay 自定义主题 MaterialAlertDialogBu​​ilder 对话框

问题描述

我的应用主题设置如下:

<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="colorOnSurface">@color/appColorOnSurface</item>
...
</style>

但是当我使用 MaterialAlertDialogBuilder 时,文本对比度非常差(因为材质对话框使用 colorOnSurface with 60% alpha,而不是 textColorPrimary)。所以我尝试使用这个 ThemeOverlay:

<style name="ThemeOverlay.App.Dialog.HighContrast" parent="ThemeOverlay.MaterialComponents.Dialog">
    <item name="colorOnSurface">@color/appColorOnSurfaceHighContrast</item>
</style>

并像这样应用它:

<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="materialAlertDialogTheme">@style/ThemeOverlay.App.Dialog.HighContrast</item>
    <item name="colorOnSurface">@color/appColorOnSurface</item>
    ...
</style>

然而,这会导致在对话框中显示项目列表时出现问题。每个项目的触摸区域仅限于显示的文本区域,而不是像往常一样拉伸对话框的宽度。

此外,主题似乎不是 Material 风格,而是 AppCompat 风格。

为什么 ThemeOverlay 方法会导致意外的触摸区域(好像 WRAP_CONTENT)问题?这不是应用 ThemeOverlay 的正确方法吗?或者还有其他方法可以让警报对话框使用 @color/appColorOnSurfaceHighContrast 吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)