Contextual Action Bar messing with Toolbar actions - android

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);
}

Related

How to hide menu icon from ActionBar

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

Menu button disappears when action bar is hidden in Kitkat

I'm developing an android app which doesn't have an action bar. I have the sign out and sync options as menu items. When I tried this in my Nexus 5, the menu button is nowhere to be found. It usually appears in the action bar. Is there a way to keep the menu button and hide the action bar at the same time?
Is there a way to keep the menu button and hide the action bar at the same time?
No. If you are not going to use the action bar, you cannot reliably use <menu> resources. Please put "sign out and sync options" in your own GUI, such as via buttons.
Note that the MENU key is itself deprecated now; few devices going forward will have one.

Split Action Bar only in Action Mode (CAB)

It is possible to have a split Action Bar only in Action Mode?
My application have only the top action bar, but it's Contextual Action Bar needs to be splitted in two (top/bottom).
I found this:
The contextual action bar is not necessarily associated with the action bar. They operate independently, even though the contextual action bar visually overtakes the action bar position.
on http://developer.android.com/guide/topics/ui/menus.html#CAB. So i think it's possible, but how?
I'm pretty confident it's not possible - and even if it is - i would cringe to see the hack.
The cab is a crafty beast that offers a lot of convenience out of the box but doesn't like to be tampered with.
The platform takes care of you fantastically by placing a CAB at the bottom if required or collapsing items , but as far as UI designs go, you should avoid relying on the bottom bar.
see https://stackoverflow.com/a/8609144/1593156 .

Android theme, fullscreen and the action bar

I have have some problems with devices that have the action bar. When running on a phone I want to go fullscreen with no title bar and no status bar. On tablets I want to show the action bar but still no title bar. Minsdk is 7! The method setTheme doesn't work when you toggle fullscreen so I can't have two themes. Is there a way to show the action bar in fullscreen mode? The support library doesn't support the Action bar.
The only reason I want to do this in the first place is cause they for no good reason at all broke the backward compability by moving the menu key to the action bar. The easy solution for this according to the docs is to add android:showAsAction="ifRoom" to the menu items. But that does absolutly nothing.
I've also tested numerous solutions I found on google that supposedly toggles fullscreen. None of them work on any of my devices so please do not point to something you've read if you haven't used it yourself.
EDIT: I Solved this. The problem seems to be that you have to specify a Holo theme to get the action bar back. Otherwise it won't show. I added this in my main Activity.
#Override
public void setTheme(int resid) {
if(isTablet(this))
{
super.setTheme(android.R.style.Theme_Holo);
return;
}
super.setTheme(resid);
}
On tablets I want to show the action bar but still no title bar
The action bar replaces the title bar. There is no concept of an activity having an action bar and a title bar.
Is there a way to show the action bar in fullscreen mode?
AFAIK, no, by definition.
The support library doesn't support the Action bar.
ActionBarSherlock provides a backport of the action bar for API Level 7 and higher.
The easy solution for this according to the docs is to add android:showAsAction="ifRoom" to the menu items. But that does absolutly nothing.
It certainly "does nothing" if you have no action bar. If you want a fullscreen experience, then you will need to roll your own menu replacement. IMHO, most fullscreen apps did this already (e.g., a game going with a game-styled "menu").

Action Bar Sherlock - Hide Actions on Collapse

I have three actions with the property SHOW_AS_ACTION_ALWAYS since I want to have the three of them always showing. However one of them has a collapse action view, and I wan't to hide the other two to have the full action bar for my layout when I click the action. Is there any way to do this?
This only seems to work if I use SHOW_AS_ACTION_IF_ROOM but this way I only get two items on the action bar instead of three.

Categories

Resources