I want an acitivy to show a Contextual Action Bar, not normal ActionBar. The reason is that I show this activity in resonse for user long-clicking an item.
I know how to hide title and in general make the normal ActionBar look similar to CAB, but not quite. May be there is a simple way of doing it?
Update:
My question is similar, but not a complete duplication of how to invoke the actionbars context menu like behavior question
The difference is that I dont want at all to show a "normal" ActionBar, always the one that looks like Contextual ActionBar.
The suggestion to move to ActionMode right in the activity onCreate.
ActionMode.Callback onDestroyActionMode() that is called when ActionMode ends, we would simply finish() the activity.
It is a good one and almost does it. There are two subtle problems with this approach.
One, there is an observable flicker when ActionBar shows and immediately goes to CAB.
Second, the more substatial one is that there is no way to differentiate between edits that we want to "accept" and "decline". I would want checkmark mean that edits need to be accepted, and "back" button mean that edits need to be discarded. Unfortunately the suggested hack results in both routes ending with the call to onDestroyActionMode()
I could have added more CAB action items, for saving or exiting without saving, but this defeats the purpose of having separate editing activity.
Related
I have a problem.
I have an action bar. It has a drop down list and it has an overflow button and another button some where in between.
Because I use a drop down, I am setting the action bar to use this mode:
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
mActionBar.setListNavigationCallbacks(mActionBarNavigationAdapter, mOnNavigationListener);
mActionBar.setDisplayShowTitleEnabled(false);
My mOnNavifationListener is set to call a REST api depending on which item I chose in the drop down list.
This works as excepted.
The problem is, if I click on the overflow button to reveal extra options (such as settings or more importantly, Signout), I still get the navigation listener activated.
So I thought. Ok let's try to distinguish between the buttons using their position or id which are passed as parameters in onNavigationItemSelected method.
So I added an if statement that checks the position parameter. But...
It seems that the position of the overflow button is ALSO 0 (exactly like the position of the first item in the drop down list, so it passes the check and calls the REST api which is not good.
Also, the third button (not the drop down list or the overflow), has a position of 1 which effectively calls the other REST api...
I can't find a way to distinguish between the items in the action bar.
Any suggestions?
First, I'd strongly consider replacing your use of list navigation, as that is officially deprecated in the "L" Developer Preview and should remain deprecated in the next shipping version of Android.
I still get the navigation listener activated
I am not clear on what you mean by this. I also don't know which action bar you are referring to:
native API Level 11+?
appcompat_v7?
ActionBarSherlock?
Ideally, onNavigationItemSelected() will be called when your activity first appears, then if the user chooses something from the Spinner. If you are saying that it is being called at other points in time, while unfortunate, this can be worked around by simply keeping track, in your own data member, of where you are in the Spinner, and only doing work if the Spinner position actually has changed. So, for example, if you start off showing position 0, and the user taps something which causes onNavigationItemSelected() to be called again with position 0, you know that nothing needs changing, because you are still on position 0.
I'm using the Navigation Drawer Example downloadable here.
I'd like to extend this example to disable the selection of one of the planets. For simplicity, lets say I want to permanently disable the selection of Saturn, and change the text of Saturn to dark gray, and have it not highlight when a user selects it. (in reality, I would like to disable navigation programmatically when a user has changed certain values on the screen not yet saved to the device).
The closest thing I've gotten to this is to stop the selectItem() method from being called from within the onItemClick click listener, but an issue remains even if I do this - the text of "Saturn" still appears selectable and highlights when a user clicks it.
What portion of the widgets do I need to change to prevent the text of Saturn from being highlighted?
I've tried changing
mDrawerLayout.setClickable(false);
mDrawerList.setClickable(false);
But neither of these options appear to have any affect.
Any suggestions or ideas as to how to approach this problem?
A couple helpful notes:
I'm aware that alternatively I can Set the Drawer Lock Mode to prevent the navigation drawer from being opened, but this is much less intuitive than having grayed out nav actions
Is the more appropriate thing to do here to remove the items from the list that cannot be accessed at this time? Similar to as described in the Remove ListView implementation here? The biggest disadvantage to this is that I would probably have to change the listview to describe why items have been removed from this list temporarily.
I'd like to extend this example to disable the selection of one of the planets
Create your own subclass of ArrayAdapter where you override areAllItemsEnabled() to return false and isEnabled() to return true or false as needed.
I want to let status bar visible but can not be pulled in my activity, is it possible?
If use getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
the status bar is invisible.
Don't do this.
I've been there before - you think you have an interaction that requires overriding some default system behavior (back button, home button, etc).
User expect those buttons (and the status bar) to behave in a certain way and will get annoyed if you override it.
Could you tell us why would you want to block StatusBar from being pulled?
As rightly pointed out by theelfismike, this isn't a best practice to follow.
I suspect you are trying to achieve something which can be gracefully done otherwise.
I have an app that in a certain Activity (drawing) can be in any one of a number of states, such as draw, erase, select, etc.
To enable these states, I've got a button for each in the ActionBar, but one thing I'd like to do is to 'show' the user which state is enabled by keeping the button pressed active or pressed until I turn it off (when they have switched state by pressing one of the other buttons).
Searches here and other places have me coming up blank... can anyone recommend a possible solution? I've though about rolling my own toolbar, and while this might be my final solution, using the ActionBar would speed things up greatly at this point.
Thanks.
There is no direct way to do that, as far as I know, but you could implement your custom component to do that. However, my advice to you is having a separate toolbar that's not on the action bar, since the users expect all buttons on the Action Bar to be "Action Items" which perform something immediate, so having toggle items on the Action Bar might break this expectation. This allows you to save space on the action bar for things that the user expects to see there like: navigation, "Undo", "Save", "Delete"...
I agree with Bruno about the fact its probably best if you do it in a separate toolbar for the sake of user experience standard and your code will probably look better because you cant fully customize the action bar but if you do decide to go with it i can think of something really simple like, when clicking one of the menu buttons you set the pressed button to a new drawable (pressed button) and the others to their normal drawable (not pressed) so each menu icon will have a pressed and not pressed icon. you will have to invalidateOptionsMenu though.
I had the same problem and did not find a solution. However, I found a workaround that works for me:
In the onOptionsItemSelected(MenuItem item) method, if item is the button you want to toggle, simply call item.setIcon() and point to another drawable. I use the same image but with another color to show the user that the button is in "pressed" state. And when the button is pressed again, revert to the original drawable.
The Title is almost the entire question but i'll complement it with some things :
-(1) I have a AsyncTask for get some data from Internet
-(2) I have a AsyncTask for display a Progress Dialog
Before call (1) , I execute (2) dialog.show() and when task (2) ends I call dialog.dimiss(). All is doing right , but while the Progress Bar is showing the Menu Button stay unresponsiveness, ie , nothing happens...
I would like to know if it is the default behavior or i missing something ?
I'm looking for it and did found anything that clear me about it..
Aprecciate any advice
You mean to say that while the dialog is showing, pressing the hard menu button does not bring up the menu. Did I get it right?
If so, then I see the same behavior as you. But according to this:
For example, when a dialog is open,
the Menu key reveals the options menu
defined for the Activity and the
volume keys modify the audio stream
used by the Activity.
So I would expect that the menu button should still work even if the dialog is showing, but based on my experience, it does not.
After the dialog is dismissed, the menu button should work again.
onCreateOptionsMenu is meant to prepare the dialog. Once it is shown and in use it is no longer being prepared and thus use of the dialog is then handled in onOptionsItemSelected.