Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to use different themes for different android versions?

MinSDKVersion = 7 TargetSDKVersion = 17

If the user have SDKVersion 11 or higher I like to set the theme to Theme.Holo.Light. It doesn't works for me here. When I launch the app on a 3.1 device it just uses the Theme.Light:

enter image description here

Same when I run this app on a device with lower version than 3.1

My Folderstructure:

enter image description here

Manifest:

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme" >

values-v11:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>


<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

other values folders:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

    <style name="MyTheme" parent="@android:style/Theme.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

How can I use this correctly?

Sincerely Marco Seiz

like image 450
Marco Seiz Avatar asked Jan 15 '13 10:01

Marco Seiz


People also ask

What is the difference between themes and styles?

A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view.

Can we install custom themes on Android smartphones?

Related. Rooted Android phones have access to custom themes that replace your home screen, notification and other system graphics. Themes need to be compatible with the specific Android-rooted ROM you currently have on the phone.

How can I change my Android app theme?

Open themes. xml (night) . In the Project pane select Android, go to app > res > values > themes > themes.


1 Answers

Why do you have your theme twice in your styles.xml file?

<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>


<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

Delete the one you don't need(In this case the Theme.Light theme):

values-v11:

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

values:

<style name="MyTheme" parent="@android:style/Theme.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

like image 153
Ahmad Avatar answered Oct 03 '22 10:10

Ahmad