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

Cos*_*Dev 0 android material-design android-textinputlayout android-textinputedittext

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

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

代码:

        <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>
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 10

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

 <com.google.android.material.textfield.TextInputLayout
    app:endIconTint="@null"
Run Code Online (Sandbox Code Playgroud)

要更改下划线颜色,您必须将boxStrokeColor属性与自定义选择器一起使用:

<com.google.android.material.textfield.TextInputLayout
    app:boxStrokeColor="@color/myselector"
Run Code Online (Sandbox Code Playgroud)

和:

<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>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

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

    <com.google.android.material.textfield.TextInputLayout
        app:endIconTint="@null"
        app:boxBackgroundColor="@color/bk_selector"
Run Code Online (Sandbox Code Playgroud)

使用如下选择器:

<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>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明