将Android Material Components版本从1.0.0更新到1.1.0,将所有颜色弄乱了

时间:2019-11-12 10:19:32

标签: android kotlin material-components material-components-android

将材料组件版本从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样式正在运行,颜色也仍然很奇怪,与更新材质组件版本之前相比。很难再涂相同的颜色。

1 个答案:

答案 0 :(得分:2)

我们正式发布了材料组件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">

收件人:

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