如何停止textinputlayout来更改endIcondrawable的颜色并仅在用户单击时更改下划线的颜色? [英] How to stop textinputlayout for changing color of the endIcondrawable and change the color of underline only when user clicks?

查看:129
本文介绍了如何停止textinputlayout来更改endIcondrawable的颜色并仅在用户单击时更改下划线的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题1::TextInputLayout正在更改endIconDrawable的颜色,默认情况下为绿色和白色,但已变为灰色,因此如何停止它?

Issue-1: TextInputLayout is changing the color of endIconDrawable, it is green and white by default but it is getting changed to grey so how do i stop it?

问题2::仅当用户单击TextInputLayout并开始键入内容时,我才想更改backgroundtint或下划线颜色.

Issue-2: I want to change the backgroundtint or underline color only when user clicks the TextInputLayout and start typing so how to do it.

代码:

        <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" 该小部件将使用默认选择器:

To avoid tinting the endIconDrawable you have to use the app:endIconTint="@null" otherwise the widget will use the default selector:

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

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

To change the underline color you have to use the boxStrokeColor attribute with a custom selector:

<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 属性:

To change the background color use the app:boxBackgroundColor attribute:

    <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>

这篇关于如何停止textinputlayout来更改endIcondrawable的颜色并仅在用户单击时更改下划线的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆