【发布时间】:2021-05-14 22:19:04
【问题描述】:
我的应用主题是这样设置的:
<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?
【问题讨论】:
标签: android android-theme android-dialogfragment android-dialog material-components-android