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把下划线变成透明的白色?
最佳答案
你可以这样试试:
为 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);
关于java - 如何以编程方式使edittext下划线透明白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41511552/