ActionBarSherlock overflow listview - android

After integrating the ActionBarSherlock in my android app I noticed that the dropdown menu that drops when the user hits the overflow button differs between 2.* and 4.*.
I have successfully customize this dropdown menu for 2.* with the right colours, but the dropdown menu in 4.* is displayed with white color andblack text and nothing that I do seems to modify this menu.
Do I need to do anything special to customize this dropdown menu in 4.*? it is even possible?
Thanks

When you add a style for ABS, you must be sure to also include the proper Android tags. E.g.
Not just
<item name="actionBarStyle">#style/ActionBar</item>
But
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
The former only controls ABS, and the library uses the standard Action Bar on 4.x.

Related

How to tint AppCompat r22.1 action bar overflow icon?

I know it's possible to replace the icon by setting a custom actionOverflowButtonStyle as described here. However, that style only allows setting a different drawable and or/background.
Instead, I would like to use the standard icon provided by AppCompat, just tinting it with a particular color, just as the drawer icon/back button can be tinted via the color attribute in drawerArrowStyle.
I have tried these methods, which reportedly used to work:
Setting colorControlNormal -- Toolbar icon tinting on Android
Setting textColorPrimary in the theme -- MenuItem tinting on AppCompat Toolbar
Setting a custom actionBarStyle and changing colorControlNormal there.
But as far as I can see none of them work with the latest AppCompat -- the overflow icon keeps its original color (while other widgets, such as TextViews or the text in menu items do change).
Should this be done differently now? I am not using a custom Toolbar view, just the default AppCompat-provided, ActionBar-like one.
How to reproduce:
Create a default Android Studio project, with minimum SDK version = 9.
This automatically includes a blank activity and a menu resource with a single menu item, "Settings", with app:showAsAction="never" which means it will be displayed in the overflow menu.
Finally, customize the styles.xml file. For example:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#008888</item>
<item name="colorControlNormal">#ff0000</item>
<item name="android:textColorPrimary">#ff0000</item>
</style>
</resources>
You'll notice that neither property affects the overflow menu icon color. Tested in a Nexus 5 with Android 5.1.1.
If you trace the Theme.AppCompat.Light.DarkActionBar theme, you see that it sets:
<item name="actionBarTheme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
Which in turn inherits from Base.ThemeOverlay.AppCompat.Dark, which sets:
<item name="android:textColorPrimary">#color/abc_primary_text_material_dark</item>
Which essentially equals white:
<color name="primary_text_default_material_dark">#ffffffff</color>
If you just inherit from Base.Theme.AppCompat.Light, you won't run into this issue since it doesn't set the actionBarTheme. You can easily customize the action bar using the material properties anyway.

Using my Lollipop theme (on Lollipop)!

I had my app looking pretty nice using the new Lollipop tools. I decided backwards compatibility is important, so I switched all my Fragments,actionBar imports to the support library. Now (understandably) I can't use my lollipop theme.
Is there a way to use different action bars for different themes? I tried to cast the support ActionBar to a new one but it doesn't seem this is allowed.
My problem lies with the following (from v21 docs)
All of your Activities must extend from ActionBarActivity, which
extends from FragmentActivity from the v4 support library, so you can
continue to use fragments. All of your themes (that want an Action
Bar/Toolbar) must inherit from Theme.AppCompat. There are variants
available, including Light and NoActionBar. When inflating anything to
be displayed on the action bar (such as a SpinnerAdapter for list
navigation in the toolbar), make sure you use the action bar’s themed
context, retrieved via getSupportActionBar().getThemedContext(). You
must use the static methods in MenuItemCompat for any action-related
calls on a MenuItem.
so by calling getsupportActionBar I can't use my Holo theme:
<resources>
<!-- Base application theme. -->
<style name="appTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
<style name="MyActionBar"
parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#color/blue_semi_transparent</item>
</style>
</resources>
Also for some reason the action bar loses the button that was on it and it goes into the dropdown menu and the app icon no longer appears in the action bar.
I really am no expert on this stuff having only started developing on lollipop so would really appreciate advice.
AppCompat (i.e., ActionBarActivity) uses the Material color palette which defines default coloring throughout your app. In your case, you need to use colorPrimary for your action bar color:
<style name="appTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue_semi_transparent</item>
</style>
Note that you should also provide a colorPrimaryDark (a darker version of the same color) for coloring the status bar.
Per the partially outdated Action Bar training, AppCompat also uses app namespaced attributes (as things like showAsAction didn't exist before API 11) for your menu items:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="ifRoom" />
...
</menu>
Per the Toolbar documentation (which is default behavior on Material themes and in AppCompat):
In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.
Therefore as you noted the app icon not appearing on the Action Bar is expected behavior.

Android Theme AppCompat how to style menu item selector

I have used Android Support V7's #style/Theme.AppCompat.Light for my styles. And to be more specific I have used Actionbar Style Generator
I want my overall theme to be in light red. So,for options menu item selector,I need light red color to work. I have made Accent color in Actionbar Style Generator to red as well. But the options menu item is always default blue. I have changed following as well to be sure
<item name="popupMenuStyle">#style/PopupMenu.Fsa</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Fsa</item>
<style name="DropDownListView.Fsa" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/red_selector</item>
</style>
But also,the options menu item selector is always default blue. I have browsed several tutorials on Actionbar styling and they were also of no help. So any help would be greatly appreciated.
Depending on your hardware needs Android Support or not, your XML must contain both item style reference:
<!-- Support library compatibility -->
<item name="popupMenuStyle">#style/PopupMenu.Fsa</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Fsa</item>
and
<!-- Support library not needed -->
<item name="android:popupMenuStyle">#style/PopupMenu.Fsa</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Fsa</item>
regardless the fact of Android Studio show error for "requires API level XX", it compiles as well and now the correct styles are applicable in both hardware, who needs and not the support library.

Theme.Holo with Dark Action Bar

I am making a daydream application and I want the settings activity to follow the same interface as the standard settings. For right now I want to make the app use the Holo theme but have a dark action bar like you can get with the Holo.Light.DarkActionBar theme. I've googled around and have not found anything similar, and I tried looking through the android source code to find out how they do it for the Settings page, but it is too big for me to handle and I cannot find the styling system.
I've got my styles set up but I cannot find the correct value to use for actionbar style. I do not have interest in adding more libraries like actionbar sherlock.
NOTE: Dark Action Bar =/= Holo actionbar.
My app only works with 4.2 and up so the Holo.Light.DarkActionBar theme should exist.
For reference, I want my app to have this theme:
The settings app uses the Widget.Holo.ActionBar.Solid for its actionBarStyle. As in:
<style name="Your.Theme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#android:style/Widget.Holo.ActionBar.Solid</item>
</style>

ActionBarsherlock how to set dividers on menu items with icons only

Hello android developers,
I know this question have been asked many of times, and I have also tried many solutions but they are not working for me.
Firstly I am using action bar sherlock library to show action bar,and I want to show dividers between menu items with icons only.
For that I create custom style for showing divider but they are not showing.
<style name="Theme.SherlockCustom" parent="#style/Theme.Sherlock.Light">
<item name="android:actionBarDivider">#drawable/actionbar_seprator</item>
<item name="android:showDividers">middle</item>
</style>
And also tried to update sherlock library ActionMenuItemView.java for ActionBar where needsDividerBefore() will always give true. But this patch also not worked for me. Please help where I am going wrong. Thanks.
You can't get dividers on versions > 4.0 for your scenario unless you use a custom view for your action bar; the native implementation controls the behavior internally and doesn't give any hook to modify that.
HTH,
Ali.

Categories

Resources