【发布时间】:2018-12-04 18:38:40
【问题描述】:
我的目标是以编程方式更改焦点 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
一些图片:
【问题讨论】:
标签: android scrollview android-textinputlayout programmatically