Kyle Horkley
Kyle Horkley

Reputation: 1001

(Android) API-specific styles?

For my Android app, I want my app to have translucent status and navigation bars on KitKat (API level 19). How do I make it so level 19 API operating systems have transparent status/navigation bars, while non-KitKat ones to have normal bars.

Upvotes: 1

Views: 2726

Answers (1)

matiash
matiash

Reputation: 55350

You need to define a custom theme, and set these properties for API level 19.

First, create a styles.xml file in res\values

It should have the following content:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyCustomTheme" parent="@android:style/Theme">
    </style>
</resources>

The parent="@android:style/Theme" may be different according to the base theme you want (e.g. Theme.Light, Theme.Holo, Theme.Holo.Light, or whatever).

Then create a similar styles.xml file in res\values-v19, with this content:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyCustomTheme" parent="@android:style/Theme.Holo">
       <item name="android:windowTranslucentStatus">true</item>
       <item name="android:windowTranslucentNavigation">true</item>
    </style>
</resources>

(Same as before, parent may be different).

And in your AndroidManifest.xml file, look for the application node, and add/update the theme attribute, i.e.

<application
    android:icon= ...
    android:theme="@style/MyCustomTheme">

Upvotes: 4

Related Questions