How can I center a menu item in an action bar? - android

How can I center a menu item in an action bar? I am using an image icon in action bar as menu but it appears at the right side of the action bar and I want to center it. Is it possible in android ?

This can be done using custom views in actionbar. In native actionbar view you can't set alignment of menu items. Check here another SO post for custom action bar

Related

Action Bar styling [Top and Bottom]

I am a beginner in android development,
I am trying to style action bar in top and bottom
like this in top
Action Bar Top
and bottom
Action Bar Bottom
I have using splitActionBarWhenNarrow to split action bar...
but I am unable to style action bar and show custom button in left or right side of action bar..
How do I achieve this?
I am using API 15 as a minimum requirement
any suggestion will be appreciated..
Use new Toolbar introduced in material design, rather than using ActionBar.
You can create your own Style.xml file with styles for customization.

Possible to have action overflow icon in top action bar of split actionbar?

Let me explain my current scenario.
I have a split action bar. From what I understand all action items will go to the bottom of the split action bar. I want to have some action items in the top action bar so I made a custom action bar by making an xml file for it.
In my onCreate, I have this to set up the top action bar...(custom_actionbar is an xml file I made.)
getActionBar().setDisplayOptions(
ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP
| ActionBar.DISPLAY_SHOW_CUSTOM);
View view = View.inflate(getApplicationContext(),
R.layout.custom_actionbar, null);
getActionBar().setCustomView(view);
So this works to set up the top of the action bar.
Now I am getting closer to my problem. I can currently get an action overflow icon in the bottom of the split action bar, but I want the icon to be at the top of the split action bar.
For a simple action bar it is possible to set the action overflow icon by doing android:showAsAction = "never" in the respective menu xml file.
HOWEVER, if I am doing a custom action bar for the top, I can not do this. This will only apply to the bottom action bar as all of the elements in the respective menu xml file will go to the bottom of a split action bar.
Does anyone know how I can get the action overflow icon to appear at the top of the split action bar or should I remodel everything in a different way? Like just have a normal action bar and then have some strip to hold image buttons at the bottom to mimic a split action bar? Or is there a way to get the elements in the menu xml file to go to the top of the split action bar?
Any Help is appreciated.
Thanks
By what i understand you want to have the overflow menu in the top action bar which is a custom xml file. You can actually mimic that overflow menu icon and the options list in the custom xml file if required. It is basically a hack to use popup windows with a list adapter to mimic the overflow menu behavior. Check the link: http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html
Hopefully this solves you problem.
So there is no real "good" way of having the action overflow button in the top of a split action bar menu. There are several ways that one could go about doing this.
Create a custom view for the top, have an image button that represents the action overflow menu icon and launch a pop up menu onClick to simulate the action overflow menu.
Create a regular (single) action bar and then create a custom view that will be at the bottom of the activity that will resemble the bottom of a split action bar. The action bar can get the action overflow menu if at-least one menu item is set to android:showAsAction = "never"
I personally went with option 2 because I could not find a suitable icon that represents the action overflow icon.

Android Action Bar drop down menu width

I want to handle the width of drop down menu on action bar. It is coming by default and title is not displayed in action bar.
In the google+ app width of drop down menu in action bar is very less. i want to have same in my app.
I am using App Compat library to use action bar.
Thanx.

Hide Action Bar while showing Split Action Bar

How can I hide the top Action Bar but show the Split Action Bar using ActionBarSherlock. I would like to have Tabs at the top instead like this:
The Android developer site states the following to hide the action bar but keep the split action bar:
If you'd like to hide the main action bar at the top, because you're
using the built-in navigation tabs along with the split action bar,
call setDisplayShowHomeEnabled(false) to disable the application icon
in the action bar. In this case, there's now nothing left in the main
action bar, so it disappears and all that’s left are the navigation
tabs at the top and the action items at the bottom, as shown by the
second device in figure 3.
https://developer.android.com/guide/practices/tablets-and-handsets.html#SplitActionBar
In my SherlockFragmentActivity I call the following, however only the app icon and title disappear and the action bar stays like this:
//Hide action bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
Calling getSupportActionBar().hide() hides the action bar but also hides the split action bar.
The tabs only roll up into the top action bar if you are using the Tabs provided by ABS. You're not using ViewPager/ViewPagerIndicator for the tabs by any chance are you? (I have this issue currently)

Android: Is it possible to hide the top part of the actionbar but keep the bottom bar with the overflow buttons

currently i am using ActionbarSherlock.
Right now, my apps has a Bar at top and a bar at the bottom with overflowed buttons.
I want a custom header bar and do not want to try to theme the Actionbar header bar, but I want to keep the bottom bar with the buttons.
Is it possible to hide the Header bar portion of the ActionBar?
ActionBar().hide() hides both top and bottom bars.
According to the action bar doc ("Using split action bar"): add uiOptions="splitActionBarWhenNarrow" to the corresponding manifest element. Then use setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false). The tabs move are moved into the - now empty - top bar.

Categories

Resources