Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherit editText from Theme.Light with Holo parent theme

I want to inherit the editText from android:Theme while my parent theme is android:Theme.Holo.Light.
Is there any "clean" way to do this short of copying the resources from the android sdk folder into my project?

like image 531
beenjaminnn Avatar asked Jun 27 '13 14:06

beenjaminnn


1 Answers

So my idea would be to have a custom theme (really just a style) that extends from android:Theme.Holo.Light, and then overwrites the EditText attributes to use the parent settings from android:Theme.

It looks like android:Theme.Holo.Light uses an editTextStyle attribute reference to change the appearance of the EditTexts:

<item name="editTextStyle">@android:style/Widget.Holo.Light.EditText</item>

So you can override it with the editTextStyle from android:Theme:

<style name="YourTheme" parent="android:Theme.Holo.Light">
    <item name="android:editTextStyle">@android:style/Widget.EditText</item>
</style>

Then, all you have to do is apply YourTheme in your manifest (or in code if you really want to) to get your custom theme. You may want to tweak stuff further, check out all the stock themes here: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

Edit

I just tested this out and realized that it appears that android:style/Widget.EditText doesn't seem to apply the background from older versions of android, most likely because it uses a reference to android:editTextBackground, which Holo.Light sets. I just tried also changing android:editTextBackground manually to the legacy EditText drawable, and it works for me.

Note: Only apply this adjustment on your styles.xml under /values-v11, since only version 3.0 and can use android:editTextBackground, and older versions of android will already use the old EditText background. If the app min is >= API 11, you don't need to worry about this.

<style name="YourTheme" parent="android:Theme.Holo.Light">
    <item name="android:editTextStyle">@android:style/Widget.EditText</item>
    <item name="android:editTextBackground">@android:drawable/edit_text</item>
</style>
like image 163
Steven Byle Avatar answered Nov 15 '22 04:11

Steven Byle