I'm trying to make my app fit with Google's best practices for material design but for some reason the items I set in my v21\styles.xml are never applied to my application.
Please take a look at the v21 styles and Android Manifest files below and tell me what I'm doing wrong that would cause my custom AppTheme to not show up.
v21\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- android theme colors -->
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#F44336</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#FFD600</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#FFD600</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.foo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"> **Theme set here**
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- Test:USB otg -->
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<!-- Test:USB otg -->
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>
</manifest>
I'm testing this code on a device that runs the most recent version of Android, API 23, so i'm not sure why the styles for API 21+ wouldn't be triggered.
Below I have also posted my App's style xml files for other platform versions, it seems that one of these is being used by the app instead. I have included these for completeness.
v14\styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
v11\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
</resources>
values\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<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="Theme.AppCompat.Light.DarkActionBar">
<!--
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="Theme.AppCompat.Light.NoActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">@style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">@android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
</resources>
Why is my app never displaying the style I have laid out in v21\styles.xml??
I found the error.
Basically, in your Manifest File, you are setting "AppTheme" for application. However, you are also setting a Theme for the activity (FullscreenTheme).
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application
android:theme="@style/AppTheme"> **Theme set here**
<activity
android:theme="@style/FullscreenTheme" >
...
</activity>
</application>
</manifest>
To Fix, I see two options:
Option1:
You can remove:
android:theme="@style/FullscreenTheme"
Option2:
If you really need to use that FullscreenTheme, added it to v21/styles.xml. Then, you can set it diferently in v21.
It is your call!