I want to use the android colorControlNormal/Activated/Highlight style property for a single EditText, not for the entire activity. Is that possible? If yes, how?
Asked
Active
Viewed 2,037 times
1 Answers
3
You can override theme attributes like android:colorControlNormal
for a particular view or hierarchy of views using the android:theme
attribute. This attribute is supported on devices running API 21+.
First, define an overlay theme. This is a theme with no parent that defines only the attributes you want to override.
res/values/styles.xml
<style name="MyThemeOverlay">
<item name="android:colorControlNormal">@color/myControlColor</item>
</style>
Then set the theme on your view or view group.
res/layout/my_layout.xml
<EditText
...
android:theme="@style/MyThemeOverlay" />

alanv
- 23,966
- 4
- 93
- 80
-
Thank you, it worked perfectly :) But will it work on Kitkat when using AppCompat? – Broadwell Mar 22 '15 at 09:01
-
Maybe! I think we support the `app:theme` attribute on a number of classes when using appcompat-v7, but I am not certain of the specifics. For general-purpose use, you can always apply the theme overlay at run-time by using a `ContextThemeWrapper` and obtaining a layout inflater from the wrapped context. – alanv Mar 22 '15 at 09:08
-
So I just tried it and the property is in fact not working on kitkat. Could you point me into any direction using ContextThemeWrapper? – Broadwell Mar 22 '15 at 11:41
-
Check [this thread](http://stackoverflow.com/questions/9469174/set-theme-for-a-fragment), which shows how to create a theme wrapper and obtain a `LayoutInflater` for it. – alanv Mar 22 '15 at 22:56
-
@Broadwell did you make it work on api level < 21 ? I tried the contextThemeWrapper but that did not work. – Shubhral Jan 24 '17 at 08:42