首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在ScrollView中更改不起作用的TextInputEditText的下划线颜色

在ScrollView中更改不起作用的TextInputEditText的下划线颜色
EN

Stack Overflow用户
提问于 2018-12-05 02:38:41
回答 2查看 1.6K关注 0票数 2

我的目标是以编程方式更改 TextInputEditText中的提示标签和下划线颜色。过了一段时间后,我终于让它们都在测试环境中工作了,但当在我真正的应用程序中实现时,下划线突然停止了工作。我把范围缩小到了ScrollView

我试着在ScrollView,TextInputEditField和TextInputLayout中调整焦点,但是都不起作用。

要更改颜色,只需使用BackgroundTintList:

代码语言:javascript
复制
    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:

EN

回答 2

Stack Overflow用户

发布于 2018-12-05 04:16:36

使用此代码更改编辑文本颜色尝试此操作

使用backgroundTint更改颜色

代码语言:javascript
复制
<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Underline color change"
        android:backgroundTint="@android:color/holo_red_light" />
票数 0
EN

Stack Overflow用户

发布于 2019-06-17 04:15:23

要以编程方式更改TextInputEditText的颜色,请使用它的setBackgroundTintList方法或用于预棒棒糖的setsetSupportBackgroundTintList

代码语言:javascript
复制
 editText.setSupportBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#F00000")));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53619455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档