简体   繁体   中英

Android application Theme overriding view theme

I have been developing an Android app for quite some time now and almost everything is how it's supposed to be. However, I'm having some issues with themes for some views. My application uses a AppCompat.Light based theme as shown bellow:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>

Everything looks white and clean, but I have one specific screen that is kind dark. So I created the following theme for some EditText fields:

<style name="InputField" parent="Theme.AppCompat"></style>

in order to make the input fields have white colors. I then run the application on devices with different Android versions. On a smartphone with Android 5.0.2, everything looks as I expected. On a smartphone with android 4.4.4, however, the input is dark. I even tried to change the theme of the input field theme to

<style name="InputField" parent="Theme.Holo"></style>

or

<style name="InputField" parent="@android:style/Widget.Holo.EditText"></style>

in the values-v19 styles, but it still looks dark. If I change the application theme to

<style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar"></style>

the input fields look as they should, but the entire rest of the app is dark themed and it's not what I want. I can only assume that application theme is having some influence over my views theme, even though I explicitly specified the theme they should use. The same behavior happens on a smartphone with android 4.2.2.

System provided styles doesn't define used colors, they have only references to a theme attributes. Colors are defined the theme, thus, it not enough, if you set parent to some system style.

Starting API 21 (5.0) you can override theme for specific views (or styles) by setting attribute android:theme . For older versions you will need to define specific colors and drawables in your style.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM