【问题标题】:Change underline color and floating hint color of TextInputLayout更改 TextInputLayout 的下划线颜色和浮动提示颜色
【发布时间】:2018-07-23 10:35:03
【问题描述】:
我在TextInputLayout 主题中使用上述属性来使TextInputLayout 的下划线颜色在激活时变为绿色。
<item name="colorControlActivated">#27e905</item>
它工作正常,我得到以下结果
但正如您所见,colorControlActivated 也会影响浮动提示颜色。我需要不同颜色的浮动提示。有什么办法可以吗?
【问题讨论】:
标签:
android
android-styles
android-textinputlayout
【解决方案1】:
2021 年更新
你可以使用这个属性来控制下划线颜色
app:boxStrokeColor="@color/green"
【解决方案2】:
在styles.xml 中添加这些样式
<style name="textInputLayout.GrayLabel"
parent="Widget.Design.TextInputLayout">
<item name="hintTextAppearance">@style/AppTheme.TextFloatLabelAppearance</item>
</style>
<style name="AppTheme.TextFloatLabelAppearance"
parent="TextAppearance.Design.Hint">
<!-- Floating label appearance here -->
<item name="android:textColor">@color/YOUR_COLOR</item>
<item name="android:textSize">@dimen/YOUR_TEXT_SIZE</item>
</style>
并像这样使用它:-
<android.support.design.widget.TextInputLayout
style="@style/textInputLayout.GrayLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_8dp">
【解决方案3】:
如果你想改变 TextInputLayout 的提示颜色,只需创建这个样式:
<style name="style">
<item name="colorAccent">your_color</item>
</style>
然后
<android.support.design.widget.TextInputLayout
...
app:theme="@style/style" />
【解决方案4】:
您可以在 style.xml 中使用这些样式
<style name="myHintText" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/YOUR_COLOR</item>
<item name="android:textSize">13sp</item>
<item name="android:textColorHint">@color/YOUR_COLOR</item>
<item name="android:colorControlHighlight">@color/YOUR_COLOR</item>
</style>
注意要求最低 api 级别 21