I have two questions. Before detailing these questions, I want to add I'm using ActionBarSherlock.
The first question would be that I am having issues with adding a divider between ActionItems in my ActionBar. In the printscreen, there are 3 dividers, for instance the first one is between the back button and Check In.
I customized my ActionBar using the style below. However, the drawable called small_detail_divider does not show up. I also tried adding this divider programmatically, using the setBackgroundSplitDrawable(). That did not help either. What should I do to add divider between those ActionItems?
<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="absForceOverflow">true</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar.Solid">
<item name="background">#drawable/top_panel_background</item>
<item name="icon">#drawable/application_logo</item>
<item name="backgroundSplit">#drawable/small_detail_divider</item>
<item name="android:background">#drawable/top_panel_background</item>
<item name="android:icon">#drawable/application_logo</item>
<item name="android:backgroundSplit">#drawable/small_detail_divider</item>
</style>
Another question would be: I want to add action items in the same manner as they are added within the printscreen. When I add the action items, they are always added to the right of the ActionBar. How can I add an action item to the left of the ActionBar such as the Back Button in the printscreen? Any suggestion would help.
the attribute you are looking for is:
<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarDivider">#drawable/small_detail_divider</item>
....
<item name="android:actionBarDivider">#drawable/small_detail_divider</item>
...
</style>
Just to give you some more info.
The split ActionBar should be set with:
<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarSplitStyle">#style/Widget.Styled.ActionBarSplit</item>
<item name="android:actionBarSplitStyle">#style/Widget.Styled.ActionBarSplit</item>
...
Then provide your custom style for the split action bar..
Thrid question: Adding in order:
When you add the menu item pragmatically use: Menu
menu.add (0, R.id.menu_new_ab_item, 0, "Item");
The order determines how you order your menu items.
You can be more specific in your menu.xml files android:orderInCategory="1..n" can be any int. I normally start at 10 or so, so I can inflate items in-front of the standard items.
Related
I'm having trouble making ActionBarToggleButton having custom selector.
I got app that works for mobile and tablet devices, and now I have to make it usable for TV devices.
To do that I have to add some custom focus selector, that is more visible then default one.
App uses NavigationView for drawer and has toggle button in action bar that opens it. Also there are other items in action bar.
I have managed to change selectors for all action bar items except toggle button via:
<item name="android:actionBarItemBackground">#drawable/selectable_selector</item>
Is there a way to customize ActionToggleButton.
I dont need to change arrow drawable, but only color of the default selector.
Thanks
In API 21 and more you only need to write this item in style.xml, in your Toolbar theme:
<item name="colorControlHighlight">#color/xxx</item>
But in lower APIs, First you should write this style in your styles.xml:
<style name="MyToolbarTheme.Navigation" parent="#android:style/Widget">
<item name="android:background">#drawable/selector_items</item>
<item name="android:scaleType">center</item>
<item name="android:minWidth">56.0dip</item>
</style>
then add this items to your toolbar theme:
<item name="actionBarItemBackground">#drawable/selector_appbar</item>
<item name="toolbarNavigationButtonStyle">#style/MyToolbarTheme.Navigation</item>
Example:
<style name="MyToolbarTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textColorPrimary">#ffffff</item>
<item name="android:textColorSecondary">#ffffff</item>
<item name="actionBarItemBackground">#drawable/selector_appbar</item>
<item name="toolbarNavigationButtonStyle">#style/MyToolbarTheme.Navigation</item>
</style>
(Sorry for my weak English)
I want show dividers between menu items in android actionbar
Icon1 | Icon2 | icon3
my code for showing menu items is
<item
android:id="#+id/menu_time"
android:icon="#drawable/action_time_btn_stateful"
android:title="time"
peel:showAsAction="always"/>
<item android:id="#+id/menu_room_change"
android:icon="#drawable/action_room_btn_stateful"
android:title="change"
peel:showAsAction="always"/>
<item
android:id="#+id/menu_like_set"
android:icon="#drawable/like_button"
android:title="Like"
peel:showAsAction="always" />
Thanks in advance.
Simply put,
your actionbar in ICS and later version is limited to show 4 items in menu.
The rest of the items can be shown when you tap on overflow menu (vertical 3 dotted line).
So adding a divider between items counts divider is also a menu item.
Did you take a look at these already :)
Is there a standard way to add dividers between action bar items in Android 3.0?
ActionBar MenuItem Divider
I suggest get your icons with divider on their left or right based on your requirement.
Not a good practice. But let me know if you find a better solution :)
Try setting custom style
<style name="CustomTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/action_bar_background</item>
<item name="android:showDividers">beginning</item>
<item name="android:divider">#color/action_bar_divider</item>
</style>
I'm struggling with styling the ActionBar. My app has an ActionBar with three tabs. I'm trying to get the selected tab to have a background color, and the unselected tabs to show a different color. I'm following this reference: Customizing Action Bar. But all the TABs are showing the Selected color.
My styles.xml file is as follows:
<style name="MyActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBar.TabBar">
<item name="android:background">#drawable/tab_background</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>
<style name="MyActionBarTabBarStyle" parent="android:style/Widget.Holo.Light.ActionBar.TabBar">
<item name="android:background">#drawable/red</item>
</style>
<style name="AppTheme.Light" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">#style/MyActionBarTabBarStyle</item>
</style>
tab_background is just a 9 patch. I'm also not sure if I'm inheriting the action bar tab from the correct parent (parent="android:style/Widget.Holo.Light.ActionBar.TabBar). I've looked through the references & find it very difficult to understand the style hierarchy
Why wont my tabs show selected or no? Thanks in advance for your assistance.
I solved my problem. I didn't use State List Drawables initially. I used the background image directly instead of going via the StateListDrawable. Using StateListDrawable, you can set a different background based on whether the tag is selected or not.
So I added the file tab_background_select.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#drawable/tab_background" />
</selector>
and I referenced this from my styles.xml:
<item name="android:background">#drawable/tab_background_select</item>
If i use sherlockActionBar with this code
menu.add(Menu.NONE, R.string.abc, Menu.NONE, R.string.abc)
.setIcon(R.drawable.ic_action_red_plus)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
It shows the icon with the text next to it on the right in UPPERCASE BOLD. Now, setting asside android icon guidelines, how can i change the color/shape of that text?
This is what i've tried but it has no effect:
<style name="MyTheme" parent="#style/Theme.Sherlock.Light">
<item name="android:textSize">20dp</item>
</style>
<style name="MyTheme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyTheme.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/MyTheme.Styled.ActionBar</item>
</style>
<style name="MyTheme.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/pdf2</item>
<item name="android:background">#drawable/logo</item>
</style>
Note that i'm not asking how to style the tabs text(which has answers on the site), but the action shown on the action bar and not the action shown in the drop down menu.
Thanks
The color is changed:
<style name="MyTheme" parent="Theme.Sherlock.Light">
<item name="android:actionMenuTextColor">#color/White</item>
<item name="actionMenuTextColor">#color/White</item>
</style>
Based on the XML layout in the ABS library, you could use
Activity.findViewById(R.id.abs__textButton)
That should return an extended version of the Android Button, which can have a custom typeface. This probably isn't a good idea because I don't think it will work on devices using a native ActionBar. You can try and see.
Also, you should not be using R.string.something as the id. You should create an id in XML and reference it using R.id.something or just define an int in you class.
EDIT:
I did some testing and if you do Activity.findViewById(menuItemId) on an ICS device you get a ViewGroup with an ImageButton and a Button. I can't give you their ids, but you could use getChildAt to get the Button child and apply the typeface to it.
Is there a way to show Divider between the Menu Items in ActionBar for HoneyComb+.
Some post says that the Divider will be shown only when the menu items has android:showAsAction="withText".
I want to show only the Icon not the Text.
I successfully shown Divider for Pre-HoneyComb by implementing a Action Bar Compatibility.
I dont want to use ActionBarSherlock as given in this post Android actionbar sherlok doesn't show divider because it will be time to change from Action Bar Compatibility to ActionBarSherlock in my all Projects.
When i saw the Android Source i found that Divider will be show only when it has text as shown below (from ActionMenuItemView)
public boolean needsDividerBefore() {
return hasText() && mItemData.getIcon() == null;
}
public boolean needsDividerAfter() {
return hasText();
}
Is there a way that I can give my Implementation for ActionMenuItemView for ActionBar where needsDividerBefore() will always give true
I found an answer by myself with help of http://android-developers.blogspot.in/2011/04/customizing-action-bar.html However, this does not completely solve my problem. It adds a divider for Title, and also one for the home Icon. There are also left and right separators. That too is adjustable.
I added android:selectableItemBackground to my theme.
<item name="android:selectableItemBackground">#drawable/action_bar_item_selector</item>
action_bar_item_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/actionbar_compat_separator"></item>
<item android:left="1dp" android:drawable="#drawable/actionbar_compat_item"></item>
</layer-list>
actionbar_compat_separator - is my seperator drawable
and actionbar_compat_item is my selector for action bar item.
EDITED
I have found a better solution to my problem. It works well.
<item name="android:actionButtonStyle">#style/ActionButton</item> to my Theme
<style name="ActionButton" parent="android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">#drawable/action_bar_item_selector</item>
</style>
You can override existing theme with custom styles, for e.g.
<style name="CustomTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/action_bar_background</item>
<item name="android:showDividers">beginning</item>
<item name="android:divider">#color/action_bar_divider</item>
</style>
Update: This doesn't seem to work for Android 5 Lollipop and above:
This is the best way I found. Just add a group with a dummy item to your menu:
menu.xml
<group>
<!--dummy item to get a nice separator-->
<item
android:title=""
android:showAsAction="always"
android:enabled="false" />
</group>
<item android:id="#+id/action_example"
...
The dummy item has an empty title so it appears invisible, and it's disabled so it can't be clicked.