Android colorControlNormal xml attributes doesn't work pre-Lollipop

只谈情不闲聊 提交于 2019-12-21 07:31:31

问题


I've been trying to change the color of the EditText line on the bottom, but my EditText still doesn't wanna change the color, but it's using the style from Material.

I've tried to change the color following these answer: link

So I have an EditText with the Material form but not the colors I've set.

I've put appcompat-v7 in my Gradle config file, and it's already working for the color primary.

<style name="AppBaseTheme.MiddleTheme.Widget.EditText" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/middle_primary</item>
    <!-- Those 3 lines are staying in red war in IntelliJ but it does build the project -->
    <item name="android:colorControlNormal">@color/middle_sqool_primary</item>
    <item name="android:colorControlActivated">@color/middle_sqool_primary</item>
    <item name="android:colorControlHighlight">@color/middle_sqool_primary</item>            
</style>

回答1:


You have to set the colorControlActivated, colorControlHighlight and colorControlNormal in your app theme (or activity theme) not in your edittext style.

Something like this:

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



回答2:


As a workaround, try using android.support.v7.widget.AppCompatEditText rather than EditText. You should always use that for programmatically created views.

Pretty sure you made it, but be sure you are editing themes in the values folder and not in the values-v21 one (if any).




回答3:


I had a similar issue. Wanted to change the highlight colour of the menu items. And none of these attributes didn't work (Support Library v25.0.0).

The only attribute that allowed me to change colour on Pre-L devices is this:

<item name="actionBarItemBackground">@drawable/YOUR_DRAWABLE</item>

I stopped searching for further workarounds because it's obvious that Support Library is NOT ready for production code.



来源:https://stackoverflow.com/questions/28882694/android-colorcontrolnormal-xml-attributes-doesnt-work-pre-lollipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!