如何停止 textinputlayout 更改 endIcondrawable 的颜色并仅在用户单击时更改下划线的颜色?

How to stop textinputlayout for changing color of the endIcondrawable and change the color of underline only when user clicks?

问题 1:TextInputLayout 正在更改 endIconDrawable 的颜色,默认情况下它是绿色和白色,但它正在变为灰色,我该如何阻止它?

问题 2: 我只想在用户单击 TextInputLayout 并开始输入时更改背景色或下划线颜色,请问如何操作。

代码:

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/d"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_10sdp"
            app:endIconMode="custom"
            app:endIconDrawable="@drawable/green"
            app:endIconContentDescription="@string/D"
            android:hint="@string/D">
            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
        </com.google.android.material.textfield.TextInputLayout>

为了避免给 endIconDrawable 着色,你必须使用 app:endIconTint="@null" 否则小部件将使用默认选择器:

 <com.google.android.material.textfield.TextInputLayout
    app:endIconTint="@null"

要更改下划线颜色,您必须使用带有自定义选择器的 boxStrokeColor 属性:

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

与:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="?attr/colorPrimary" android:state_focused="true"/>  <-- this line
  <item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
  <item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>

要更改背景颜色,请使用 app:boxBackgroundColor 属性:

    <com.google.android.material.textfield.TextInputLayout
        app:endIconTint="@null"
        app:boxBackgroundColor="@color/bk_selector"

选择器如:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_focused="true"/>  <-- this line
  <item android:alpha="0.04" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
</selector>