Android: styling overflow menu in action bar - android

I am using v7 support library in my project. My manifest settings are:
android:minSdkVersion="7"
android:targetSdkVersion="15"
I used Android Action Bar Style Generator to generate styles for my Action Bar. The problem is that while everything works for the newest apis, my overflow menu does not change in low apis (tested on emulator 2.2 and real device 2.3.3 htc desire).
(this should have red background)
Is menu overflow loading items in some other component like spinner dialog or something (sry if that sounds dumb) ? Why styles for one api(ex 15) doesn't apply for other(ex 8), and is there anything i can do to have same overflow menu for all api versions.
This is my original generated style from Action Bar Style Generator which i tweaked a lot but with no success.
<resources>
<style name="Theme.Example" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_example</item>
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Example</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="actionDropDownStyle">#style/DropDownNav.Example</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="actionModeBackground">#drawable/cab_background_top_example</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_example</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Example</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.Example.Widget</item>
</style>
<style name="ActionBar.Solid.Example" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_example</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_example</item>
<item name="progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="ActionBar.Transparent.Example" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/ab_transparent_example</item>
<item name="progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="PopupMenu.Example" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>
<style name="DropDownListView.Example" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_example</item>
</style>
<style name="ActionBarTabStyle.Example" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example</item>
</style>
<style name="DropDownNav.Example" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_example</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
<item name="android:dropDownSelector">#drawable/selectable_background_example</item>
</style>
<style name="ProgressBar.Example" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_example</item>
</style>
<style name="ActionButton.CloseMode.Example" parent="#style/Widget.AppCompat.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_example</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Example.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Example</item>
</style>

I did it this way:
<style name="Theme.yourapp" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/Theme.yourapp.Widget</item>
</style>
<style name="Theme.yourapp.Widget" parent="#style/Theme.AppCompat">
<item name="android:textColor">#android:color/black</item>
</style>

For simplicity, the android: namespace pertains to anything built into the OS while anything without android: as the namespace would pertain to your application (and the libraries you are using). Most, if not all, support libraries for the ActionBar will try to use the native ActionBar implementation and therefor use the android: namespace attributes in your styles. When the native ActionBar is not available it would use the libraries implementation and the non-android: namespaced attributes. This is why you must specify every attribute with and without the android: namespace.

Related

appcompat 23.2.1 menuitem text small case issue

I have added appcompat 23.2.1 support library.This library gives menu item text small for lollipop and above version devices but its shows in small case but its not shows in small case for older versions(It shows in capital ).I have used below code for it
=screnshot
<style name="Theme.app" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarTabTextStyle">#style/MyTabTextStyle</item>
<item name="android:textAllCaps">false</item>
<item name="android:actionBarTabTextStyle">#style/MyTabTextStyle</item>
<item name="actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
<!-- Main theme colors -->
<item name="android:textColorPrimary">#color/white</item>
<item name="android:colorPrimary">#color/actionbartop</item>
<item name="android:colorPrimaryDark">#color/actionbartop</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyMenuTextAppearance" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
<item name="textAllCaps">false</item>
<item name="android:textSize">#dimen/default_textsize_menu</item>
</style>
you may use , android:capitalize="none" in layout

Android action bar autosrollable title

I'd like to create app with setTitle function at ActionBar
But, some strings are bigger than ActionBar width, and i want use autoscrollable function for my title.
I try to create style for my ActionBar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_background</item>
<item name="android:titleTextStyle">#style/ActionBarTitleStyle</item>
<!-- Support library compatibility -->
<item name="background">#drawable/ab_background</item>
<item name="titleTextStyle">#style/ActionBarTitleStyle</item>
</style>
<style name="ActionBarTitleStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">1</item>
<item name="android:singleLine">true</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:textColor">#FF64A3</item>
</style>
But it doesn't work.
Please tell me what i do wrong?

How do I change the style(color) of tabs in action bar v7 of android ?

I'm trying this to change the color and style of tabs in action bar using the v7 support library. But only the color of action bar is changed not the tabs. Please tell me what I'm doing wrong.
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/TabStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<style name="TabStyle"
parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="background">#drawable/tab_bar_background</item>
</style>
Try this (if you use actionbar tabs):
<style name="ActionBarTabs" parent="#style/Widget.AppCompat.Light.ActionBar.TabView.Inverse">
<item name="titleTextStyle">#style/ActionBarTitle</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="background">#drawable/tab_bar_background</item>
<item name="android:background">#drawable/tab_bar_background</item>
</style>
<style name="ActionBarTabBar" parent="#style/Widget.AppCompat.Light.ActionBar.TabBar.Inverse">
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/list_divider_holo_light</item>
<item name="android:dividerPadding">8dp</item>
<item name="android:background">#color/actionbar_background</item>
</style>
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#android:color/black</item>
</style>
and in your theme:
<style name="AppTheme" parent="#style/AppBaseTheme">
...
<item name="android:actionBarTabStyle">#style/ActionBarTabs</item>
<item name="actionBarTabStyle">#style/ActionBarTabs</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionBarTabBarStyle">#style/ActionBarTabBar</item>
<item name="actionBarTabBarStyle">#style/ActionBarTabBar</item>
...
</style>
If you want to change the color of the menu items in the action bar you have to set the actionMenuTextColor in your theme style.
<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionMenuTextColor">#24598a</item>
<item name="actionMenuTextColor">#24598a</item>
</style>
To customise tabs color, I suppose you should change your TabStyle item to be :
<item name="android:actionBarTabBarStyle">#style/TabStyle</item>
override "android:actionBarTabBarStyle" rather than "android:actionBarTabStyle"

Common styles for v10 and v11+?

I'm using the v7 support library in order to have an ActionBar on API Level 10+ (that's Android 2.3.3+). Now, I want to customize the look a bit, so I added an application theme. Excerpt of my values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
</style>
This works fine on Android 2.3.3, where the compat stuff is used. However, on Android 4.3 on an N4 (or an emulator), the styles are not applied. If I change the styles.xml file to:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
(notice the added android: prefix) it works on 4.3, but doesn't on 2.3 (styles not applied).
Is there any way I can get around this without specifying each <item> twice, once with the prefix and once without?
There is a perfect example on the google docs site:
http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:backgroundStacked">#drawable/actionbar_background</item>
<item name="android:backgroundSplit">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/actionbar_background</item>
<item name="backgroundSplit">#drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
Is there any way I can get around this without specifying each <item>
twice, once with the prefix and once without?
Another way would be to create version specific res/values-XX folders.
Since the divide is version 10 and versions 10+, you can create res/values-v10/styles.xml containing:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
</style>
Let versions 10+ deal with the default res/values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
Still, it isn't much different from specifying <item></item> twice.
For reference, you can look at the project structure of ActionBarSherlock. That should provide you some pointers.
You can also take a look at: Applying Styles and Themes to the UI. Scroll down to sub-section Select a theme based on platform version.
If I have not misunderstand your issue, you can collapse it together this way
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
<item name="background">#drawable/bg_actionbar</item>
</style>
In my experience, this way eclipse gives compile time errors every time you change somethings inside styles.xml (due of lint if I remember good), but clean and rebuild make those errors go away.

Styling Action Bar Sherlock

I am trying to implement styling on my Action Bar Sherlock on the following:
Basically the actionbar overflow is to be styled in regards to its background color. I did try the following approach.
<style name="GCTheme" parent="Theme.Sherlock.Light">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#FFFFFF</item>
<item name="actionDropDownStyle">#style/MyDropDown</item>
</style>
<style name="MyDropDown" parent="Widget.Sherlock.Spinner.DropDown.ActionBar">
<item name="android:popupBackground">#7D7D7D</item>
</style>
I also did try implementing the android:actionMenuTextColor and also the android:actionOverflowButton but it says that API 11 or higher is required... Any idea on how this is to be implemented ? Please help.
<style name="GCTheme" parent="Theme.Sherlock.Light">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#FFFFFF</item>
<item name="actionDropDownStyle">#style/MyDropDown</item>
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:background">#00BFFF</item>
</style>
<style name="MyDropDown" parent="Widget.Sherlock.Spinner.DropDown.ActionBar">
<item name="android:popupBackground">#7D7D7D</item>
</style>
<style name="PopupMenu.Example" parent="#style/Widget.Sherlock.Light.ListPopupWindow">
<item name="android:popupBackground">#7D7D7D</item>
</style>

Categories

Resources