首页 > 解决方案 > 如果我把它放在 AppBarLayout 中,为什么 TextInputLayout 颜色不会改变?

问题描述

我试图改变 TextInputLayout 颜色并且它工作得很好,但是一旦我把它放在 AppBarLayout 中它就不会改变。

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="220dp"
    >

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:boxBackgroundColor="@color/white">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/weightText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/weight"
            android:inputType="number" />

    </com.google.android.material.textfield.TextInputLayout>

如您所见,TextInputLayout 与 AppBarLayout 的颜色相同,但它应该是白色的。

标签: androidxmlandroid-layoutmaterial-design

解决方案


显然这只是Android Studio预览的错误,在模拟器上完美运行

在此处输入图像描述


推荐阅读