使用 appcompat v7 更改 EditText 底线颜色 [英] Changing EditText bottom line color with appcompat v7

查看:25
本文介绍了使用 appcompat v7 更改 EditText 底线颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 appcompat v7 在 Android 5 及更低版本上获得一致的外观.它工作得很好.但是我无法弄清楚如何更改 EditTexts 的底线颜色和强调色.是否可以?

I am using appcompat v7 to get the look consistent on Android 5 and less. It works rather well. However I cannot figure out how to change the bottom line color and the accent color for EditTexts. Is it possible?

我试图定义一个自定义的 android:editTextStyle(参见下面),但我只成功地改变了完整的背景颜色或文本颜色,而不是底线或强调色.是否有要使用的特定属性值?我是否必须通过 android:background 属性使用自定义可绘制图像?不能在 hexa 中指定颜色吗?

I have tried to define a custom android:editTextStyle (cf. below) but I only succeeded to change the full background color or text color but not the bottom line nor the accent color. Is there a specific property value to use? do I have to use a custom drawable image through the android:background property? is it not possible to specify a color in hexa?

 <style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
     <item name="android:editTextStyle">@style/Widget.App.EditText</item>
 </style>

 <style name="Widget.App.EditText" parent="Widget.AppCompat.EditText">
     ???
 </style>

根据 android API 21 来源,带有材料设计的 EditTexts 似乎使用 colorControlActivatedcolorControlNormal.因此,我尝试在之前的样式定义中覆盖这些属性,但没有效果.可能 appcompat 不使用它.不幸的是,我找不到带有材料设计的 appcompat 最新版本的来源.

According to android API 21 sources, EditTexts with material design seem to use colorControlActivated and colorControlNormal. Therefore, I have tried to override these properties in the previous style definition but it has no effect. Probably appcompat does not use it. Unfortunately, I cannot find the sources for the last version of appcompat with material design.

推荐答案

终于找到了解决方案.它只包括覆盖应用主题定义中 colorControlActivatedcolorControlHighlightcolorControlNormal 的值,而不是你的 edittext 样式.然后,考虑将此主题用于您想要的任何活动.下面是一个例子:

Finally, I have found a solution. It simply consists of overriding the value for colorControlActivated, colorControlHighlight and colorControlNormal in your app theme definition and not your edittext style. Then, think to use this theme for whatever activity you desire. Below is an example:

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">#c5c5c5</item>
    <item name="colorControlActivated">@color/accent</item>
    <item name="colorControlHighlight">@color/accent</item>
</style>

这篇关于使用 appcompat v7 更改 EditText 底线颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆