问题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>
答案 0 :(得分:3)
为避免着色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>