How to hide the menu Button (3 vertical dots) from ActionBar, I created custom action bar but some devices still showing default menu icon on right side ActionBar.
I just want to hide menu Button (3 vertical dots) but not the menu functionality.
Here is the screenshot
It is called a Overflow and one way to hide it is overriding your onPrepareOptionsMenu method and find the overflow button and set its visibility to false
sample:
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
menu.findItem(R.id.menu_settings).setVisible(false);
return super.onPrepareOptionsMenu(menu);
}
get the menu icon at the extreme right of the action bar
Either:
You have defined items to appear in the overflow area, in which case, get rid of those, or
Your android:targetSdkVersion is under 11, in which case, raise it
see this post for more information
http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html
Related
I'm using appcompat v7 and the support design libraries. In my activity there is a regular toolbar, which has three action buttons (RM1, RM2, RM3):
_____________________________________
RM1 RM2 RM3 |
_____________________________________|
And when some items are long-clicked in a list, a contextual action bar (CAB) is shown instead of the regular toolbar. My CAB has a single action (CM).
_____________________________________
CM |
_____________________________________|
When the contextual action bar (CAB) is activated, it hides the regular toolbar. At this point if I click on the contextual menu (CM), everything is ok. But for some reason, if I click over the empty space to the left of CM, the regular menus RM1 and RM2 are shown, despite the regular toolbar being hidden by the CAB. RM1 and RM2 icons are obviously not shown when the CAB is active, but the click handlers are still in place and they are fired even though the regular toolbar is hidden. The CAB is not intercepting the clicks unless it has an action in the clicked point. If I click over CM, it is handled correctly: RM is not shown because that button is exactly below the CM menu.
Is this a bug? Any workaround?
Tested in an Android 4.1 device.
I consider it a bug. I have run into it myself, and isolated it. Here is a workaround, assuming you are extending AppCompatActivity:
#Override
public void onSupportActionModeStarted(ActionMode mode) {
super.onSupportActionModeStarted(mode);
rm1.setEnabled(false);
rm2.setEnabled(false);
rm3.setEnabled(false);
}
#Override
public void onSupportActionModeFinished(ActionMode mode) {
super.onSupportActionModeFinished(mode);
rm1.setEnabled(true);
rm2.setEnabled(true);
rm3.setEnabled(true);
}
I have seen a lot of similar questions to mine, but they all seem to differ in some way that makes them not so helpful.
I have a split action bar in my activity. I have customized the top action bar to display my own view since I wanted to add icons to the top and not show the launcher icon or activity title. I have added a menu with icons which appears at the bottom. Here is the code that does both these things:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basic_fractions);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
View view = View.inflate(this,R.layout.action_bar_top,null);
actionBar.setCustomView(view, new ActionBar.LayoutParams(Gravity.RIGHT | Gravity.CENTER_VERTICAL));;
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_basic_fractions, menu);
return true;
}
This code produces the effect I wanted - a split menu with some icon buttons at the top (from the layout view) and some at the bottom (from the menu)
However, I want to add a drop down list to the top action bar. I have found ways to do it if I had a menu there instead of a layout view (for example with submenus or actionLayout), but not with this mixed kind of action bar.
An alternative would be if I could add a menu instead of a layout to be in the top action bar since I am not adding anything special, just a few normal menu buttons, but I couldn't find anyway to force them to appear in the top action bar without making it a layout like this.
Thanks for your help.
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
This is one of my items of actionbar -
<item
android:id="#+id/mode"
android:icon="#drawable/ic_action_ring_volume"
android:showAsAction="ifRoom"
android:title="#string/Ringing_Mode"/>
Here i am using ifRoom in showAsAction . Now it may or may not show on action bar according to the space available. How can i detect if it's showing in overflow menu or its actually displayed on action bar ? (I am not using ActionBarSherlock)
If you are using ActionBarSherlock you can look for the boolean value abs__split_action_bar_is_narrow
Create static method where you can do
return ResourcesCompat.getResources_getBoolean(context,
R.bool.abs__split_action_bar_is_narrow);
you need to use the ResourcesCompat (from actionbarsherlock) class.
This will Provide you,if it's showing in overflow menu or its actually displayed on action bar.
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.