如何停止文本输入布局改变endIcondrawable的颜色,只在用户点击时才改变下划线的颜色?

问题描述 投票:0回答:1

问题-1.文本输入布局(textinputlayout)改变endIconDrawable的颜色,并且只在用户点击时改变下划线的颜色。 TextInputLayout改变了endIconDrawable的颜色,默认是绿色和白色,但现在却变成了灰色,如何阻止?

问题-2.TextInputLayout改变了endIconDrawable的颜色,默认是绿色和白色,但现在却变成了灰色,我如何阻止? 我想只在用户点击TextInputLayout并开始打字时才改变背景色或下划线的颜色,怎么做呢?

代码-1: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>
android material-design android-textinputlayout android-textinputedittext
1个回答
1
投票

为了避免给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>

enter image description here

要改变背景颜色,使用 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>

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.