Search code examples
androidandroid-4.2-jelly-bean

Common practice for using Android themes dealing with versions


As I understand, preserving native look and feel is the recommended practice on android, but I can't help but notice that the default components compiled are not displayed as Holo on Jellybean. Does this mean that we must specify Holo in the version 11 folder styles.xml and have defaul elsewhere? It just seems counterintuitive to specify a custom theme to achieve a native experience.


Solution

  • When coding for multiple platform versions, you do need to specify a theme.

    Under res/values/styles.xml, you should have something like:

    <resources>
        <style name="AppTheme" parent="@android:style/Theme.Black" />
    </resources>
    

    And then in res/values-v11/styles.xml

    <resources>  
        <style name="AppTheme" parent="@android:style/Theme.Holo" />
    </resources>
    

    Then in your AndroidManifest.xml, you should specify the theme as:

    android:theme="@style/AppTheme"
    

    However, if you don't specify any theme at all (so no android:theme attribute), Android should automatically go to the device's default theme.