从1.0.0版本更新Android Material Components到1.1.0版本后,颜色混乱了。

7

我将Material Components版本从1.0.0更新到1.1.1后,应用程序内的颜色混乱了。例如,强调色未起作用,按钮颜色未应用,底部导航视图变成黑色。请帮忙解决,谢谢!

values/style.xml(此处样式不起作用):

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Button" parent="@style/Widget.MaterialComponents.Button">
    <item name="cornerRadius">@dimen/button_radius</item>
    <item name="fontFamily">@font/lato_regular_400</item>
    <item name="android:textAllCaps">false</item>
</style>
<style name="Button.Next">
    <item name="fontFamily">@font/lato_bold_700</item>
    <item name="android:textSize">@dimen/_18pxsp</item>
    <item name="android:textAllCaps">false</item>
    <item name="cornerRadius">@dimen/_40sdp</item>
</style>

values-v23/style.xml(这里的样式有效):

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowLightStatusBar">true</item>
</style>

button.xml:

<com.google.android.material.button.MaterialButton
        android:id="@+id/btn_save"
        style="@style/Button.Next"
        android:layout_width="@dimen/button_width"
        android:onClick="@{click}"
        android:layout_height="@dimen/button_height"
        android:layout_marginBottom="@dimen/_20pxdp"
        android:text="@{buttonText}" />

即使使用v23样式,与更新材料组件版本之前相比,所有颜色仍然非常奇怪。很难将相同的颜色应用回去。


没有详细信息,我们很难为您提供帮助。请发布您的应用程序主题和一个包含启动按钮的布局作为示例。 - Gabriele Mariotti
@GabrieleMariotti但是当我使用“com.google.android.material:material:1.0.0”时,我没有遇到这个问题,这是版本1.1.0的新格式吗?样式实际上是有效的,只是颜色无法正常工作。 - yao
1.1.0版本对库中的许多功能进行了更改(1.0.0版本是一年前发布的),并更改了主题。 尝试在您的情况下使用Theme.MaterialComponents.Light.DarkActionBar.Bridge - Gabriele Mariotti
你成功了吗,@yao? - Rashad.Z
@yao,你可以在这篇文章中查看我对支持暗黑和明亮主题的回答: https://stackoverflow.com/a/60093738/1950784 - Rashad.Z
显示剩余3条评论
1个回答

2
我们已经正式发布了Material Components 1.1.0版本。请尝试使用parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge"。查看文档,请访问https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#bridge-themes-bridge-themes。如果您无法将主题继承自Material Components主题,则可以继承自Material Components Bridge主题。
<style name="Theme.MyApp" parent="**Theme.MaterialComponents.Light.Bridge**">
    <!-- ... -->
</style>

在您的情况下进行更改:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">

To:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">

桥对我有用,但只有一部分。我的应用栏中的文本颜色已更改,而我的主题中的“colorOnPrimary”未解决我的问题。有什么想法吗? - Quentin vk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接