Android: How to handle theming for older SDK's - android

I have an app that is minSDK 10, target's 14. I'd love to use the Light.Holo Theme (if available for device--and falls back to light theme for older device). Is there a way I can do this this?
It seems it defaults to Dark.Holo when you target 14, but when I try to add any other theme, it overwrites it and makes it look older on newer devices.

You need to provide separate styles for both platforms to ensure that the correct style will be found at runtime.
In your res/values/styles.xml file, create the following style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Light" />
</resources>
In your res/values-v11/styles.xml file, create the following style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo.Light" />
</resources>
In your AndroidManifest.xml file, use the following line for your application's theme:
android:theme="#style/Theme.MyTheme"

I think these answers might fit: Set Holo theme in older Android versions?
Basically they're recommending copying the themes into your own project so they're available to all users

Related

Configure Eclipse for Material Design

How do I configure My App to use Material Theme. I don't wanna use Android Studio because its too slow and freezes a lot. I have read the instructions from answer to similar question.
I followed the steps but I didn't get values-21 folder as mentioned in the answer. What can I do now?
There is no difference at project folders structure in this case in Eclipse and AS, maybe you just can't get right preview at Eclipse.
I'm assuming that you currently have a folder res/values that has a file styles.xml which contains your apps theme. Manually create a folder res/values-v21 and copy your styles.xml into it. Modify the new file now so that it uses the material theme as its parent.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.Material">
<!-- Customize your theme here. -->
</style>
</resources>
Now when your app is run on a device/emulator running API 21+ it will use the Material theme.

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.

Holo Theme and API 8

I have an app that must be supported from API 8+. But I also like to have my app the holo theme for(11+). I know it won't be supported as the min sdk is 8. So the only solution will be to create 2 separate apps one for 8-11 and one for 11+. Is there any better way to do this? So that I can reduce double maintenance.
There's no need to create two separate apps. You just need to create two definitions of theme for your app:
styles.xml in /res/values-v11 (Will be used only on API 11+)
<resources>
<style name="app_theme" parent="android:Theme.Holo.Light"/>
</resources>
styles.xml in /res/values
<resources>
<style name="app_theme" parent="android:Theme.Light"/>
</resources>
and then, apply it to your application in AndroidManifest.xml:
<application
...
android:theme="#style/app_theme"
>
...
</application>
This setup uses resource qualifiers. You can read more about them here.
You can try the HoloEverywhere library to use Holo theme on Android 2.1+. It also integrates well with ActionBarSherlock.

Holo light theme not setting on button

I am building a sample application based on latest version of Android OS..As per instructions given here I am trying to give holo:light theme to only one button in my application. How do i do it ? I have created a myStyles.xml in res/values folder but I am not able to find property to apply holo-light theme.
This is what i have in myStyles.xml file
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="mybutton" parent="android:Theme.Holo.Light">
<item name="android:background">#android:color/holo_orange_light</item>
<item name="android:textColor">#android:color/holo_blue_dark</item>
</style>
</resources>
this is i have in my activity.
<Button
android:id="#+id/button1"
style="#style/mybutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lol" />
I can confirm that backgroundcolor and textcolor are getting applied...(done this for testing purpose).
Currently, If i add android:theme="#android:style/Theme.Holo.Light" to AndroidManifest.xml, holo light theme is applied to entire application. However, I want this theme to be applied for only few controls ( in this case a single button control).
A theme is a style applied to an entire Activity or application, rather than an individual View.
Thus, what you are asking for is not possible. That being said, it seems odd that you would want to do this anyway. I suggest applying the holo theme to your entire app, and then customizing your Buttons only if you really need to. This is probably what the user will expect from your application.

Android - how to set background color of all screens?

What is the best practice to maintain styles of fonts and colors. I made a colors.xml file which I have used to change colors on seperate elements like buttons, but I am not sure how Android wants developers to organize their styles.
For example, I would like all screens to have the same background color. How do I do that? Is it something I need to specify for each Activity layout xml? Or elsewhere? How do I accomplish it?
A quick and easy way to make sure every activity has the same background color, is to create a theme for your activities to use. That theme would specify the android:windowBackground.
First define the color in values/colors.xml
<resources>
<color name="background">#FF0000 </color>
</resources>
Create a themes.xml file in res/values that references that color:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>
... and then in your AndroidManifest.xml specify this as the theme for your activities to use.
<activity
android:name=".MyActivity"
android:theme="#style/MyTheme" />
Update your android studio to 1.4 it has inbuilt theme editor. as you can see in below image
You can also set the background at the application level in AndroidManifest.xml
<application
...
android:theme="#style/MyTheme">
(Note: I cannot this as a comment of the accepted answer as my reputation is too low).

Categories

Resources