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.
Related
I was curious, since I couldn't really find anything on this, if there was a way to do what happens, when you say have tabs with android, for a normal action button. Onclick on the button, I was curious if there was a way to highlight the bottom of it like the below image. Please give me your thoughts, right now, I can switch the image fine, but I am really looking for just an indication while they are inside that buttons fragment to see as is shown below where movies has the highlighted bar under it. So for my menuitem when they click it until they go back, to normalize it, I was curious if I could get this functionality somehow.
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.
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 wanted to achieve the same sort of functionality found in Google Now where you can tap the cards overflow icon and a menu appears next to it with options (shown here).
Does anyone know how to implement this sort thing to achieve the same style etc?
I think you can do this by placing a listview under your button, and set its visibility to invisible.
Then place an onclicklistener on your button to turn your visibility to visible.
So I can change the color of a options menu item no problem. However, I would like to change the color that menu items flash when pressed from green to orange. Everywhere I look has nothing on this. Please help.
If you want it to change the color of the menu item while having your finger pressed down on the button, before actually releasing it, you likely want to look into an onKeyDown() event handler. In that handler, I would change the color of the menu item, and then in the onKeyUp() handler, change the color back.
There might be a more elegant way of handling this, however. You can visit the Android SDK UI Event Handlers page for more information.