com.google.android.material.textfield.TextInputLayout 的 boxStrokeColor 无效

boxStrokeColor with com.google.android.material.textfield.TextInputLayout is not work

我在我的应用程序中使用了 TextInputLayout,我想更改 boxStroke 颜色。我用 app:boxStrokeColor = "@color/white"改变Box Stroke颜色,但是BoxStrokeColor的颜色没有改变。

但是当我将以下代码块添加到color.xml中时,当我在应用程序中使用它时,它会影响应用程序中所有TextInputLayout 的boxStrokeColor。

@color/white 我该如何解决这个问题? 相关代码块

<com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColorHint="@color/LightBlue"
            android:theme="@style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
            app:boxStrokeColor="@color/white"
            app:boxStrokeWidth="3dp"
            app:startIconTint="@color/white">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/numberOfPlayer_txt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:textColor="@color/gold"


                />

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

风格:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="AppBaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
        <item name="android:windowBackground">@color/Thistle</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined" parent="">
        <item name="colorPrimary">@color/white</item>
        <item name="boxCornerRadiusBottomEnd">20dp</item>
        <item name="boxCornerRadiusBottomStart">20dp</item>
        <item name="boxCornerRadiusTopEnd">20dp</item>
        <item name="boxCornerRadiusTopStart">20dp</item>
        <item name="android:hint">Number of player</item>
        <item name="hintTextColor">@color/card1</item>
        <item name="startIconDrawable">@drawable/ic_people</item>

    </style>

implementation 'com.google.android.material:material:1.1.0'

如果属性 boxStrokeColor 不是颜色状态列表而只是一个值,它的值将应用于框的焦点状态。

定义一个选择器而不是单一颜色:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/white" android:state_focused="true"/>
    <item android:color="@color/...." android:state_hovered="true"/>
    <item android:color="@color/...." android:state_enabled="false"/>
    <item android:color="@color/...."/>
</selector>

和:

<com.google.android.material.textfield.TextInputLayout
       app:boxStrokeColor="@color/selector"
       ...>