Reputation: 3284
I'm trying to learn how to Style my application using the styles.xml file and I need some clarification on a few things to understand it.
In an Item, what is the difference between setting android:actionbarstyle
and just actionbarstyle
? I know that in this particular case, I have to define both, but why? And what about all other cases, for example android:colorPrimary
and just colorPrimary
? In that case I get an error saying that android:colorPrimary
can only be used with min API level 21. So does someone have a good explanation on what the android:
prefix does and how it affects my app?
Is there a reference to the different parent styles, such as parent="@style/Widget.AppCompat.Light.ActionBar
and what they mean? How do I find a list of the different parent styles available for a specific item and what I can "override" in them? Right now, it's mostly guessing on my part....
Just as a reference, I'm posting my current styles.xml file.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="MyTheme"/>
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionBarTheme">@style/MyTheme.ActionBarTheme</item>
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="colorPrimary">@color/my_green</item>
<item name="colorPrimaryDark">@color/my_forest</item>
<item name="colorAccent">@color/my_soil</item>
<item name="drawerArrowStyle">@style/MyTheme.DrawerArrowStyle</item>
<item name="android:actionOverflowButtonStyle">@style/MyTheme.OverFlow</item>
<item name="android:actionMenuTextColor">@color/white</item>
<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
<item name="android:homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
<item name="colorControlNormal">@color/my_green</item>
<item name="colorControlActivated">@color/my_forest</item>
<item name="colorControlHighlight">@color/my_deep_green</item>
</style>
<style name="MyTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- This sets the BACK arrow to white. Otherwise it's black. Must be placed in the theme-->
<item name="colorControlNormal">@color/white</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/my_green</item>
<item name="background">@color/my_green</item>
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="colorControlNormal">@color/white</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
<style name="MyTheme.DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@color/white</item>
</style>
<style name="MyTheme.OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:tint">@color/white</item>
</style>
</resources>
Upvotes: 4
Views: 1070
Reputation: 8073
I will try my best to explain and will concentrate on:
<item name="colorPrimary">@color/my_green</item>
<item name="colorPrimaryDark">@color/my_forest</item>
<item name="colorAccent">@color/my_soil</item>
These attributes are regularly available with API level 21. In general you use attributes with the "android" prefix.
If you define all your styles in the styles.xml of your values folder and if you are using app compat, then you need both.
Without the prefix the attributes applies for pre L devices. i.e. App Compat. To get it work for L devices and higher you need to specifiy the attribute again with the "android" prefix.
And to get the other Android styles you can step into them, like you step into classes and the implementations. For Mac I press the command button and then click with the mouse on the specific style.
Upvotes: 3