我设计的应用程序如下所示:
但是将材质库版本从
com.google.android.material:material:1.10.0
更新到com.google.android.material:material:1.11.0
后,顶部应用栏看起来像这样:
除了材质版本之外,我没有更改任何内容。并且在布局文件中,没有
MaterialToolbar
或AppBarLayout
。如果主题中没有任何 NoActionBar
,则这是默认显示的顶部应用程序栏。
我希望顶部应用栏即使在更改材质版本后也保持不变。
我的大部分活动都使用这种类型的顶部应用栏。因此,如果您能告诉我一个仅涉及主题更改的解决方案,那就太好了。
我已经通过以下方式定义了我的应用程序的主题
主题.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.Material3.DayNight">
<item name="colorPrimary">@color/md_theme_light_primary</item>
<item name="colorOnPrimary">@color/md_theme_light_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_light_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/md_theme_light_onPrimaryContainer</item>
<item name="colorSecondary">@color/md_theme_light_secondary</item>
<item name="colorOnSecondary">@color/md_theme_light_onSecondary</item>
<item name="colorSecondaryContainer">@color/md_theme_light_secondaryContainer</item>
<item name="colorOnSecondaryContainer">@color/md_theme_light_onSecondaryContainer</item>
<item name="colorTertiary">@color/md_theme_light_tertiary</item>
<item name="colorOnTertiary">@color/md_theme_light_onTertiary</item>
<item name="colorTertiaryContainer">@color/md_theme_light_tertiaryContainer</item>
<item name="colorOnTertiaryContainer">@color/md_theme_light_onTertiaryContainer</item>
<item name="colorError">@color/md_theme_light_error</item>
<item name="colorErrorContainer">@color/md_theme_light_errorContainer</item>
<item name="colorOnError">@color/md_theme_light_onError</item>
<item name="colorOnErrorContainer">@color/md_theme_light_onErrorContainer</item>
<item name="android:colorBackground">@color/md_theme_light_background</item>
<item name="colorOnBackground">@color/md_theme_light_onBackground</item>
<item name="colorSurface">@color/md_theme_light_surface</item>
<item name="colorOnSurface">@color/md_theme_light_onSurface</item>
<item name="colorSurfaceVariant">@color/md_theme_light_surfaceVariant</item>
<item name="colorOnSurfaceVariant">@color/md_theme_light_onSurfaceVariant</item>
<item name="colorOutline">@color/md_theme_light_outline</item>
<item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_light_inversePrimary</item>
</style>
<style name="AppTheme.NoActionBar" parent="AppTheme">
<!-- Remove the ActionBar -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/honey_dew</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_foreground</item>
<item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>
</style>
</resources>
颜色.xml
<color name="seed">#5ACB6B</color>
<color name="md_theme_light_primary">#006E27</color>
<color name="md_theme_light_onPrimary">#FFFFFF</color>
<color name="md_theme_light_primaryContainer">#89FB94</color>
<color name="md_theme_light_onPrimaryContainer">#002107</color>
<color name="md_theme_light_secondary">#516350</color>
<color name="md_theme_light_onSecondary">#FFFFFF</color>
<color name="md_theme_light_secondaryContainer">#D4E8D0</color>
<color name="md_theme_light_onSecondaryContainer">#101F10</color>
<color name="md_theme_light_tertiary">#5E4CBD</color>
<color name="md_theme_light_onTertiary">#FFFFFF</color>
<color name="md_theme_light_tertiaryContainer">#E5DEFF</color>
<color name="md_theme_light_onTertiaryContainer">#1A0063</color>
<color name="md_theme_light_error">#BA1A1A</color>
<color name="md_theme_light_errorContainer">#FFDAD6</color>
<color name="md_theme_light_onError">#FFFFFF</color>
<color name="md_theme_light_onErrorContainer">#410002</color>
<color name="md_theme_light_background">#FCFDF7</color>
<color name="md_theme_light_onBackground">#1A1C19</color>
<color name="md_theme_light_surface">#FCFDF7</color>
<color name="md_theme_light_onSurface">#1A1C19</color>
<color name="md_theme_light_surfaceVariant">#DEE5D9</color>
<color name="md_theme_light_onSurfaceVariant">#424940</color>
<color name="md_theme_light_outline">#72796F</color>
<color name="md_theme_light_inverseOnSurface">#F0F1EB</color>
<color name="md_theme_light_inverseSurface">#2F312D</color>
<color name="md_theme_light_inversePrimary">#6DDE7B</color>
<color name="md_theme_light_shadow">#000000</color>
<color name="md_theme_light_surfaceTint">#006E27</color>
<color name="md_theme_light_outlineVariant">#C2C9BD</color>
<color name="md_theme_light_scrim">#000000</color>
<color name="md_theme_dark_primary">#6DDE7B</color>
<color name="md_theme_dark_onPrimary">#003911</color>
<color name="md_theme_dark_primaryContainer">#00531C</color>
<color name="md_theme_dark_onPrimaryContainer">#89FB94</color>
<color name="md_theme_dark_secondary">#B9CCB5</color>
<color name="md_theme_dark_onSecondary">#243424</color>
<color name="md_theme_dark_secondaryContainer">#3A4B39</color>
<color name="md_theme_dark_onSecondaryContainer">#D4E8D0</color>
<color name="md_theme_dark_tertiary">#C8BFFF</color>
<color name="md_theme_dark_onTertiary">#2F138D</color>
<color name="md_theme_dark_tertiaryContainer">#4632A4</color>
<color name="md_theme_dark_onTertiaryContainer">#E5DEFF</color>
<color name="md_theme_dark_error">#FFB4AB</color>
<color name="md_theme_dark_errorContainer">#93000A</color>
<color name="md_theme_dark_onError">#690005</color>
<color name="md_theme_dark_onErrorContainer">#FFDAD6</color>
<color name="md_theme_dark_background">#1A1C19</color>
<color name="md_theme_dark_onBackground">#E2E3DD</color>
<color name="md_theme_dark_surface">#1A1C19</color>
<color name="md_theme_dark_onSurface">#E2E3DD</color>
<color name="md_theme_dark_surfaceVariant">#424940</color>
<color name="md_theme_dark_onSurfaceVariant">#C2C9BD</color>
<color name="md_theme_dark_outline">#8C9389</color>
<color name="md_theme_dark_inverseOnSurface">#1A1C19</color>
<color name="md_theme_dark_inverseSurface">#E2E3DD</color>
<color name="md_theme_dark_inversePrimary">#006E27</color>
<color name="md_theme_dark_shadow">#000000</color>
<color name="md_theme_dark_surfaceTint">#6DDE7B</color>
<color name="md_theme_dark_outlineVariant">#424940</color>
<color name="md_theme_dark_scrim">#000000</color>
同样的问题,你找到解决办法了吗?
我这样做是为了修复它。但我不喜欢这个解决方案:
<style name="AppTheme.Actionbar" parent="Widget.Material3.ActionBar.Solid">
<item name="background">@color/your_color</item>
</style>
<style name="your_theme" parent="Theme.Material3.Light">
<item name="actionBarStyle">@style/AppTheme.Actionbar</item>
</style>