【问题标题】:How to change line and hint colors of TextInputEditText programmatically?如何以编程方式更改 TextInputEditText 的线条和提示颜色?
【发布时间】:2020-02-15 16:58:53
【问题描述】:

1) 从服务器获取颜色

2) 将 TextInputEditText 的行和提示更改为 颜色(适用于所有州)

  • 我正在使用材料:1.0.0 for androidx

【问题讨论】:

  • 请添加更多上下文,例如您尝试过的示例代码

标签: android android-textinputlayout material-components material-components-android textinputlayout


【解决方案1】:

设置你可以使用的颜色:

// Sets the text color used by the hint in both the collapsed and expanded states
textInputLayout.setDefaultHintTextColor(...);

//Sets the collapsed hint text color
textInputLayout.setHintTextColor(....);

在 FilledBox 布局中更改下划线颜色可以使用方法setBoxStrokeColor

setBoxStrokeColor(ContextCompat.getColor(this,R.color....));

您可以使用单一颜色或选择器,例如:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="?attr/colorPrimary" android:state_focused="true"/>
  <item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
  <item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>

【讨论】:

  • 谢谢,线条颜色?
  • 不起作用` ` setBoxStrokeColor(Color.GREEN)跨度>
  • 不适用于 material:1.0.01.1.0-beta01 的行 - 它会崩溃
  • 使用资源 R.color.xxxxx
  • 不起作用或崩溃?这是不一样的。发布您的崩溃。
猜你喜欢
  • 2017-12-17
  • 2018-11-03
  • 1970-01-01
  • 1970-01-01
  • 2019-04-28
  • 2016-07-03
  • 1970-01-01
  • 2018-01-06
  • 2020-01-25
相关资源
最近更新 更多