假设我有一个出生日期的编辑文本输入:
我想动态改变它的状态然后被禁用,并让它有一个虚线下划线来表明它被禁用:
我该怎么做?它将根据 google material design guidelines :
最佳答案
在drawable文件夹中创建一个drawable underline.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@android:color/black"
android:dashGap="3.0dp"
android:dashWidth="1dp" />
</shape>
</item>
然后以编程方式应用此可绘制对象并将其设置为禁用
editText=(EditText)findViewById(R.id.your_edittext);
editText.setEnabled(false);
editText.setBackgroundResource(R.drawable.underline);
输出:
关于android - 禁用时更改 EditText 下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49871085/