I am currently working on some changes to my app to properly target the new Android 5.0 Lollipop that has just been released.
I have the following in my styles.xml files in the values-v21 directory
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/actionBarTabStyle</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/appPrimaryColour</item>
</style>
<style name="actionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/white</item>
</style>
</resources>
I've changed the theme but I have customised my action bar with the following for the old Holo theme
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
and
<style name="actionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabText">
I can't find what the equivalent would be for Lollipop, I've tried #android:style/Widget.Material.Light.ActionBar.Solid.Inverse #android:style/Widget.Material.ActionBar.TabText" but it then says it can't find the resources.
Just extend from Theme.Material.Light.DarkActionBar, which sets up the action bar theme to point to Theme.Material (dark) values for background and foreground colors. Also, you should be setting colorPrimary, colorPrimaryDark, and colorAccent in your AppTheme rather than manually setting the action bar background color.
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">#color/appPrimaryColour</item>
<item name="android:colorPrimaryDark"> ... </item>
<item name="android:colorAccent"> ... </item>
</style>
Related
I have this in my style.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<!--<item name="colorPrimary">#color/colorPrimary</item>-->
<!--<item name="colorAccent">#color/colorAccent</item>-->
<item name="android:windowBackground">#color/white</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="LoginScreenTheme" parent="AppTheme">
<item name="android:textColor">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="colorPrimaryDark">#color/login_background_dark</item>
</style>
<style name="LoginEditTextTheme" parent="AppTheme">
<item name="colorControlNormal">#color/login_edit_text_hint_color</item>
<item name="colorControlActivated">#color/login_edit_text_accent</item>
<item name="colorControlHighlight">#color/login_edit_text_accent</item>
<item name="android:textColorHint">#color/login_edit_text_hint_color</item>
<item name="android:textColorPrimary">#color/white</item>
</style>
<style name="LoginErrorFloatingLabelTheme" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">#color/login_error_floating_label_color</item>
</style>
<style name="ActionBarTheme" parent="AppTheme">
<item name="android:background">#color/home_primary_color</item>
</style>
<style name="LoginWaitingProgressBar" parent="AppTheme">
<item name="colorAccent">#color/orange_light</item>
</style>
</resources>
On devices with Lollipop and upper everything is alright, but on pre-lollipop there are wrong colors. It's look like theme is not applied to the devices with pre-lollipop android version. After googling I found that people are adviced to remove 'android:' prefix before every item in AppCompat theme but it doesn't work for me coz android studio doesn't see items after that.
The reason was that I didn't extend AppCompatActivity. When I changed it everything became okay.
colorPrimary , colorPrimaryDark and colorAccent items are available on only API 21+.If you want to apply them on pre lollipop devices you must move your current styles.xml file to values-v21 and create a new styles.xml on values folder and use the correct item for pre lollipop.
Check out android developers for more https://developer.android.com/guide/topics/ui/themes.html
I have been trying to set white text on the actionbar. I went through many questions and I am using theme Theme.AppCompat.Light.DarkActionBar and currently using this xml:
<style name="TrasnparentActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/TransparentActionBar</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="TransparentActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/actionbar_transparent_background</item>
<item name="android:titleTextStyle">#style/TransparentTransparentActionBarText</item>
</style>
<style name="TransparentTransparentActionBarText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
I have tried different combinations for eg: setting android:titleTextStyle, actionmenutextcolor, or using the actionBar Style Generator. None are working for me.
The above code is from values-v11 but a similar code is in values folder too.
#drawable/actionbar_transparent_background is just a shape with <solid android:color="#00000000"/>
In order to have white text (so dark action bar with light theme) you have to inherit your actionbar style from the correct object: Widget.AppCompat.Light.ActionBar.Solid.Inverse and not Widget.AppCompat.ActionBar.Solid
Here is the style.xml file :
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- action bar -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
i'm trying to create the a flat action bar without shadow
attached image:
my style xml
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:background">#drawable/white_bg</item>
<item name="android:displayOptions"></item>
</style>
I'm supporting android 4.x
Any ideas ? I tried changing the style to Solid/Inverse didn't work..
white_bg attached (It's hard to see since it's white)
it should look like this
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:background">#drawable/white_bg</item>
<item name="android:displayOptions"></item>
</style>
The null windowContentOverlay attribute should be set on your Activity theme (CustomActionBarTheme), not on the ActionBar theme.
I am trying to change the text color of a action menu item on the action bar. Using app compat. Also the overflow icon doesnt change too. Here is my custom styled styles.xml files.
res/values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the default namespace affects API levels 7-13 -->
<item name="actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the default namespace affects API levels 7-13 -->
<item name="background">#drawable/bg_action_bar</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
res/values-14/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/bg_action_bar</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#color/font_half_white</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
res/colors.xml
#F3F3F3
The text color still black doesnt change to white. Has anybody successfully changed the action menu text color. Please suggest some insights. I am testing on 4.4 Nexus5 device.
Use
<item name="android:actionMenuTextColor">#color/font_half_white</item>
// added style directly
Instead of
<item name="android:actionMenuTextColor">#style/MyActionButtonStyle</item>
in res/values-14/styles.xml
In res/values/styles.xml
<item name="actionMenuTextColor">#color/font_half_white</item>
I used a Red Color for testing. See the Action menu Item Home that is red in the snap
Edit:
Full Code
In res/values-14/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. -->
<item name="android:actionMenuTextColor">#color/red</item>
</style>
</resources>
Then in res/values/stles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
<item name="actionMenuTextColor">#color/red</item>
</style>
</resources>
In manifest
android:theme="#style/AppBaseTheme" >
Another snap
You can use this to change the text of the Action Bar irrespective of your appcompat version.Give the desired color's hex code and add this in the onCreate().
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>Some Title</font>"));
Check that in your layout xml file you don't have an android:theme attribute specified for your <Toolbar>, which would have priority over the main theme
Override your actionBarStyle attribute as pointed out everywhere over the internets.
I was working hard to achieve this but I had no luck. What I tried to do is to change the background color from the style that I attached in my main style tag. This is my code:
<resources>
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item ></item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#2E495E</item>
</style>
Still nothing changed.
I get this in my application:
http://i.imgur.com/m1MrGwk.png
I had the same issue and it's probably the same problem you were having. Notice the docs say the following:
each style property that you declare must be declared twice..
So my issue was I declared it for 2.1 and up, but not for 3.0 and greater so my Galaxy S4 of course could not see any changes to the colours I was making.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!--Support Library compatibility-->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/green</item>
<!--Support Library compatibility-->
<item name="background">#color/green</item>
</style>
<style name="NoActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
Is this the only style.xml you have? Else check if you are modifying
for the right API