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?
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With