你需要使用
StateListDrawable
为此
-
StateListDrawable是一个在XML中定义的可绘制对象,它使用几个不同的图像来表示同一图形,具体取决于对象的状态。
样例代码
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint Text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edt_bg"
android:visibility="visible" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint Text">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edt_bg"
android:visibility="visible" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
@可牵引/EDT_-bg
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/edt_bg_selected" android:state_focused="true" />
<item android:drawable="@drawable/edt_bg_normal" android:state_focused="false" />
</selector>
@可绘图/EDT_bg_已选择
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="-3dp"
android:right="-3dp"
android:top="-3dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#0fe4e4" />
<solid android:color="#00ffffff" />
</shape>
</item>
</layer-list>
@可牵引/EDT_bg_正常
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="-3dp"
android:right="-3dp"
android:top="-3dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#000" />
<solid android:color="#00ffffff" />
</shape>
</item>
</layer-list>
产量
注释
使用
android:width="2dp"
和
android:color="#000"
根据您的要求,在您的
TextInputEditText