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
Related
If I don't use show as action=always when creating a menu will it create a menu on the bottom like the old school android phones. I'm trying to create something that has like the facebook mobile tabs on the bottom, and has them for every screen. Or should I actually just make tabs for every screen?
You may be interested in a "split action bar". That way your items could appear at the bottom. showAsAction controls how/if the item appear in the Action Bar.
More information here: http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
If that doesn't look of interest then yes.. you should use tabs (or a view of some sort) at the bottom to render your "menu items".
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.
I want to make a action-bar drop-down-menu that shows items (icons) horizontally. Like this:
This is suppose to be a action-bar withe drop-down menu, where you can choose a color.
So it should show the icons (colors) horizontally and the icons should be clickable. Until now I have only managed to make a vertical list.
If possible I would like to do this in XML.
The ActionBar is not designed for such a use-case. The ActionBar buttons are meant to replace the old options menu that could be triggered with a separate hardware button on older devices (pre HC/ICS). The overflow button (the one with the 3 dots) that you've drawn in your sketch is used when there isn't enough room to show all buttons (the Android framework takes care of this automatically), so those will be grouped in the overflow menu. Overriding this behavior is a bad idea (if even possible).
Instead you should consider another approach: Add one ActionButton to the ActionBar that is meant to handle the color chooser. When this button is clicked the best solution is to show an AlertDialog (you can easily insert your on Views here that show the colors you want) because this will work best even if the button is hidden in the overflow menu.
Alternatively you could trigger a PopupMenu or implement some QuickAction to handle the color chooser (this will probably suck if your button is hidden in the overflow menu and will also lead to a very confusing UI).
I'd like to use a drop-down menu for letting the user choose an action (in this case, they select some items from a list, and use the menu to select "delete", "move" etc.)
The way Spinner works is quite close to what I want, except Spinner is clearly designed for selecting some data, rather than issuing a command.
Before it is clicked, I'd like the drop-down menu to just look like an arrow (no adjacent space for displaying the 'currently selected' data
Ideally the drop-down menu would appear directly beneath the arrow, rather than in the middle of the screen.
Items in the menu shouldn't have a radio button to indicate whether they are selected
Is there a component that is more appropriate for this than Spinner, or should I achieve these goals by tweaking a Spinner?
You should use a ContextMenu to do what you are looking for. In the dev guide there is a page about menus and a section about ContextMenus that will help with the implementation. If you put some time in skinning this menu you can change the look to match what you want.
may be i not getting you but You can use actionsheet which you can handle as you want
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.