【问题标题】:Changing underline color of TextInputEditText not working inside ScrollView更改 TextInputEditText 的下划线颜色在 ScrollView 中不起作用
【发布时间】: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


    【解决方案1】:

    使用此代码更改编辑文本颜色 试试这个

    使用 backgroundTint 改变颜色

    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Underline color change"
            android:backgroundTint="@android:color/holo_red_light" />
    

    【讨论】:

    • 抱歉,我正在尝试以编程方式更改 TextInputEditText 的颜色
    【解决方案2】:

    要以编程方式更改 TextInputEditText 的颜色,请使用 setBackgroundTintList 方法或 setsetSupportBackgroundTintList 用于 pre-lollipop

     editText.setSupportBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#F00000")));
    

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 2012-07-02
      • 2012-09-15
      • 2011-12-02
      • 2020-04-21
      • 2015-04-08
      • 2017-07-23
      • 1970-01-01
      相关资源
      最近更新 更多