没有扩展Theme.MaterialComponent的Android MaterialAlertDialog。

问题描述 投票:1回答:1

我从'Theme.AppCompat.Light.NoActionBar'延伸出来,我不想把我的AppTheme切换到MaterialDesign上。

MaterialAlertDialogBuilder(context, R.style.MaterialDialog)
            .setCancelable(false)
            .setMessage(message)
            .setPositiveButton("OK") { dialog, _ -> dialog.dismiss() }
            .show()
<style name="MaterialDialog" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorSurface">#ffffff</item>
    </style>

预期的

What I expected:

结果:我从'Theme.AppCompat.Light.NoActionBar'延伸出来,我不想把我的AppTheme切换到MaterialDesign MaterialAlertDialogBuilder(context, R.style.Material)。

What I got:

android material-design android-alertdialog material-components-android material-components
1个回答
1
投票

如果你不能移动到一个Material Components主题,你应该使用一个 桥梁主题. 类似的东西。

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
    <item name="colorSurface">#ffffff</item>
    ...
</style>

然后在你的代码中使用:

MaterialAlertDialogBuilder(context)
   .setCancelable(false)
   ...

如果你只想覆盖对话框的颜色,只需使用:

MaterialAlertDialogBuilder(context,R.style.MaterialDialog)
   .setCancelable(false)
   ...

with:

  <style name="MaterialDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="materialThemeOverlay">@style/AlertDialogOverlay</item>
  </style>  


  <style name="AlertDialogOverlay">
    <item name="colorOnSurface">@color/....</item>
    <item name="colorSurface">#ffffff</item>
    <item name="colorPrimary">@color/.....</item>
    ....
  </style>
© www.soinside.com 2019 - 2024. All rights reserved.