ActionBar buttons that support pressed state, perhaps?

I have an application that in a specific Activity (figure) can be in any of several states, such as draw, erase, select, etc.

To enable these states, I have a button for each in the ActionBar , but one thing I would like to do is show the โ€œuserโ€ whose state is on by holding the button down or pressed until I turn it off (when they switched by pressing one of the other buttons).

Searches here and elsewhere, I come up to you ... can someone recommend a possible solution? However, I am going to flip my own toolbar, and although this may be my final decision, using ActionBar will significantly speed up the work at this stage.

Thanks.

+4
source share
3 answers

There is no direct way to do this, as far as I know, but you can implement your custom component for this. However, my advice for you is a separate toolbar that is not in the action bar, as users expect all the buttons in the action bar to be โ€œAction Itemsโ€ that do something immediately, so include items in the action bar may cause breakdown waiting. This allows you to save space on the action bar for things that the user expects to see there, for example: "Cancel", "Save", "Delete" ...

0
source

I agree with Bruno that this is probably best if you do it on a separate toolbar for your convenience, and your code will probably look better because you cannot fully customize the action bar, but if you decide to go with it, I can think of something very simple when, when you press one of the menu buttons, you press the button on the new popped (pressed button), and the rest on their normal ability to pull (not pressed), so each menu icon will be pressed and not pressed. you will have to invalidateOptionsMenu though.

0
source

I had the same problem and could 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 switch, just call item.setIcon() and point to another option. I use the same image, but with a different color, to show the user that the button is in the pressed state. And when the button is pressed again, return to the original image.

0
source

Source: https://habr.com/ru/post/1391696/


All Articles