Android ActionBar setCheckable() not working - android

I'm trying to make one of the MenuItems on my Menu have a checkmark ability, but it doesn't seem to work. All other MenuItems are working, this one does too, except for the checkmark display. What am I doing wrong?
MenuItem actionPickMode = menu.add(0, 3, 0, "pickmode");
actionPickMode.setTitle("Pick Mode");
actionPickMode.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT
| MenuItem.SHOW_AS_ACTION_ALWAYS);
actionPickMode.setVisible(true);
actionPickMode.setCheckable(true);

Looks like you're trying to add a checkmark to a MenuItem that is actually on the Action Bar. According to this question it isn't possible: Android action bar checkable menu item does not work/show properly?
What you can do is implement it yourself--when the item is clicked, use setIcon to change the drawable, and maintain the state of the toggle yourself. This question describes how you can get the built-in checkmark Drawables: How to access checkmark drawable in Android OS?

You have to create a custom layout for your action containing a checkbox. See my answer here.

Related

Android Switch in Bottom Navigation

I want to have a Switch in the Bottom Navigation to set the online/offline state of the user like below Image:
The menu itself should be dynamic so i built it manually with:
menu.add(Menu.NONE, R.id.navigation_dashboard, Menu.NONE, "").setIcon(R.drawable.ic_app)
Is there a way to achieve this and add a switch to this? I accomplished the this in iOS by setting a switch to the frame of the bottom navigation bar item.
Are you asking about having the button color change, when that item is selected? If so, this is done automatically for you, using the BottomNavigationView component.
Do be aware, that you will need to supply a "StateListDrawable" (this is a fancy way to say list of icons, that represent different selected states) instead of just a drawable for this icon:
https://developer.android.com/reference/android/graphics/drawable/StateListDrawable

How might I keep a menuItem selected and highlighted in android

I have already looked at how to highlight a menu item on selection? and I am also using Android Action Bar Style Generator. They are both essentially saying the same thing, from what I can tell. And neither does what I need. When I click on a menuItem. I want the item to remain highlight, until I click another one which would in turn become highlighted. How do I do that? I have even tried enabling a menuItem but seems to have no effect either. There seems to be no option to set a menu item as selected or focussed. So does anyone know how I might do this?

Android Actionbar PopupMenu with Custom Item Layouts

I am working on an Android application where I have to design a menu which will populate from the action bar, like this:
I have tried my best but was not able to produce it using the Android controls.
The solutions I have tried are:
With Actionbar, add a menu item with a group with selectable="all", that produces the layout I need but when I click a checkbox for selecting it, the whole menu hides and selection is not done, moreover the menu icon in actionbar does not have the bottom right white arrow.
Tried creating a custom ActionProvider and added the menu items using class's OnPrepareSubMenu method but had the same issue.
I just need a push in the right direction and I can do the rest, suggestions are more than welcome.
Thank you :)
Use popupWindow.
In that you can make any custom layout and set it as content of your popupwindow and also you can specify an ANCHOR in your case it would be
R.id.your_menu_item
set a listener and listen the changes.

Custom Overflow Menu Outside of ActionBar

I need to implement a custom overflow menu with menu items and the overflow icon if the screen size cannot show all the icons. I cannot use a side scroll since I am already inside an expanded list view. I cannot use the Top or bottom action bar menu because the action will change based on what list item has been expanded.
So I would like to create my own overflow menu - similar to the gmail screenshots attached
Any ideas? Apparently ABS can be used for this but I can't figure it out, please help :)
ListPopupWindow is what you're looking for. It's an API 11+ class, however. ABS includes a backported version which is basically just a ListView inside a PopupWindow (both API 1 classes).

android submenu header icon

I'm new to Android.
I'm learning to make menu and submenu now but stumbled upon a problem.
I want to change the submenu header icon in the xml but don't know how to.
I tried to change the header icon programatically but there's no method to get the submenu(only add submenu).
Is it possible to change the header icon in the xml?
I saw codes that add submenu programatically and change the header there.
Is it weird to make the submenu in the xml?
Thanks.
edit: why I cannot type 'Hi' at the first sentence?
MenuItem newSubMenu = mainMenu.add("SubMenu");
newSubMenu.method....

Categories

Resources