[英]How to make edittext underline transparent white programmatically
View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
editText.getBackground().setColorFilter(ContextCompat.getColor(getActivity().getApplicationContext(),R.color.ed_background), PorterDuff.Mode.SRC_ATOP);
} else {
int color = Color.parseColor("#FFFFFF");
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
};
<color name="ed_background">#33FFFFFF</color>
这使编辑文本下划线为黑色,但我希望它是透明的白色。 使用 xml 设置自定义样式也会将其设置为黑色。 如何使用java使下划线变成透明的白色?
你可以像这样尝试: edittext_lined.xml
drawable xml for ex edittext_lined.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke android:color="@color/ed_background" android:width="1dp"/>
</shape>
</item>
然后在代码中:
editText.setBackgroundResource(R.drawable.edittext_lined);
只需在 xml 布局/代码中将 edittext 背景颜色设置为白色/透明即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.