Android application Theme overriding view theme - android

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.

Related

Change Full-Screen Background on App Startup (Android 5.11 Using Custom Theme)

Issue
I'm attempting to change the background (colour/drawable) during the 'cold start' phase of my apps' launch.
I have a few test devices and I've created a simple custom theme which overrides the background attribute of the parent theme. When I launch my app, on my Android 10 device the background shows perfectly fine and full-screen (whether a colour or drawable).
On my Android 5.1 (Lollipop) device, I get no such luck and the background is just plain black.
Theme Code
This is how I've setup my theme in values/styles.xml...
<style name="MyTheme" parent =
"#android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen">
<item name="android:background">#drawable/myDrawable</item>
</style>
Note: 'myDrawable' is defined (it's just a bitmap image). As mentioned, it doesn't apply on Android 5.1 during startup. Same if I just set a hex color value ('#ffffff' for example).
Am I misunderstanding something, or do I need to do something different for older devices?
You should use
<item name="android:windowBackground">#drawable/myDrawable</item>

Set theme programatically to Android system preview window

I have an app in which the user can choose between the default theme and a dark theme. The manifest applies AppTheme to the <application>, while each activity checks the relevant flag and uses setTheme(AppTheme.Dark) if necessary.
This implementation works well for all my activities, but the preview window shown by the OS before the application launches uses the Manifest theme, i.e. the light one. So users get a sudden white screen before reaching the dark app.
Based on other SO answers, I gathered that the only customization we can do is to set a windowBackground drawable for the window to use (and a statusBarColor if needed).
Even though I have two different windowBackground set for each theme, I can't change the theme for the preview window since the Application class seems to load after it, and setting theme there makes no difference.
I'd like to avoid disabling the preview since it adds a noticeable delay without much indication that the app is launching. Is there any solution to this? I'm considering having a dark color for both themes in the worst case, like the Reddit app does.
Styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- primary and accent color attributes -->
<item name="android:windowBackground">#color/activityBackgroundLight</item>
</style>
<style name="AppTheme.Dark" parent="AppTheme">
<!-- primary and accent color attributes -->
<item name="android:windowBackground">#color/activityBackgroundDark</item>
</style>
Note: While I'm using colors here, I've already tried with a gradient drawable and it doesn't change anything.
UPDATE: I wasn't able to get any other method, so I went ahead and applied the dark theme by default on the SplashActivity. This means the preview window is always dark, while the check in the SplashActivity's onCreate is inverted (compared to other activities) and applies the light theme if needed.
Still looking for a solution that actually lets me switch at runtime.

Properly set SeekBar style for Holo and pre-Holo APIs

After setting SeekBar with Holo style, I got warning that it's not supported pre-Holo APIs.
If I leave it this way, will this crash the app or pull pre-Holo style anyway? It does not crash on the emulator and I don't have 2.3.3 device.
The reason for asking his is odd behaviour. I tried to manually set style for Holo and pre-Holo using res/values-v11/ directories and placing styles.xml in each and setting the style of SeekBar to style="#style/settings_seekbar" .
Style for API 11+ looked like this
<style name="settings_seekbar">
<item name="android:seekBarStyle">#android:style/Widget.Holo.SeekBar</item>
</style>
and style for APIs older than 11 looked like this
<style name="settings_seekbar">
<item name="android:seekBarStyle">#android:style/Widget.SeekBar</item>
</style>
So it looked like this would work. But on either device with Android 4.0+, I don't see Holo's theme, but the old thick-yellow theme.
If this is the proper way of settings styles (in case the first solution will crash a device), where did I make a mistake thus Holo theme never appeared on newer devices?
It seems we can safely use a theme from the upper SDK because I found no indicators that it will ever crash the app.
If the theme does not exist, Android will use the appropriate lower-level theme.
The error we can see on the image is just a warning that UI will not look the same in the SDKs which do not support this theme.

Designing Android Themes

Can anyone tell me how I can change my apps theme from the default ones made available? Holo and Holo.Light get a bit boring after a while.
The likes of Facebook, Google+, BBC Weather, Viber, Vine and Twitter all look very professional and have their own theme whereas the app I'm developing looks quite boring.
Is it possible to change the font of the text in my app? I know it's possible to change the colour and size of it.
Another thing which would be useful to know would be how to change the colour of the action bar that is used for my app. Currently it's black but I wouldn't mind changing it to a different colour than those used by the Android default themes (e.g. purple, green, blue, etc)
Maybe you can share some tips on what you think works well for Android design?
You can generate a custom theme at http://jgilfelt.github.io/android-actionbarstylegenerator/
If you only want to change a few font an colors etc take a closer look at this (source:http://developer.android.com/guide/topics/ui/themes.html)
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
(Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.)
Now use CustomTheme instead of Theme.Light inside the Android Manifest:
<activity android:theme="#style/CustomTheme">

Android - apply theme from older API

I would like to deploy my app on APIs 8-17. However, for purely aesthetic reasons I would like to apply the default theme as it appears on api 8 as the theme for the app across all API levels.
For example, the older theme has an edittext that has an orangeish border around it, whereas the newer them uses a borderless blue line.
By limiting which APIs i deploy too I have been able to accomplish this but that isn't really a solution.
Does anyone know how this can be accomplished?
Thanks
Update
For whatever reason applying "Theme" as the theme did not force it to revert to the "Theme" theme, but instead left it as the default Holo. Using the answers below I simply called "Theme" as the parent in my custom theme (without altering any of its attributes) and set it as my application theme in the manifest. This solved it.
In your res/values directory, you can have a themes.xml file with:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="#android:Theme">
</style>
</resources>
Your app theme will now subclass from default Theme instead of Theme.Holo and you should be able to get older theme on newer android versions as well.
If you're using the default theme, it will be different between the API levels. However in the styles, you can create a custom Theme, modify an existing Theme or give a different Theme to each different API of your choice.

Categories

Resources