我的目标是以编程方式更改 TextInputEditText中的提示标签和下划线颜色。过了一段时间后,我终于让它们都在测试环境中工作了,但当在我真正的应用程序中实现时,下划线突然停止了工作。我把范围缩小到了ScrollView
我试着在ScrollView,TextInputEditField和TextInputLayout中调整焦点,但是都不起作用。
要更改颜色,只需使用BackgroundTintList:
int[][] states = new int[][] {
new int[] {android.R.attr.state_focused},
new int[] {android.R.attr.state_enabled},
};
int[] colors = new int[] {
Color.CYAN,
Color.BLUE,
};
ColorStateList myList = new ColorStateList(states, colors);
ViewCompat.setBackgroundTintList(edit, myList);
重现测试应用:https://github.com/guiquintelas/textinputedittext-underline-color
下面是一些imgs:
发布于 2018-12-05 04:16:36
使用此代码更改编辑文本颜色尝试此操作
使用backgroundTint更改颜色
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
android:backgroundTint="@android:color/holo_red_light" />
发布于 2019-06-17 04:15:23
要以编程方式更改TextInputEditText的颜色,请使用它的setBackgroundTintList
方法或用于预棒棒糖的setsetSupportBackgroundTintList
editText.setSupportBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#F00000")));
https://stackoverflow.com/questions/53619455
复制相似问题