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....
Related
I have created options menu it has some attributes like android:I'd, android : title,android:icon etc how can I set a image as android option menu and also I want title of the item below the icon not beside the icon
You cannot do this easily and you should not. What you explain sounds more like Tabs to me, which you could use instead. With these you'll get text below the icon out of the box.
I was wondering if you can just put plain text as a button in the action bar. I was messing around with a spinner, but i just dont really care for how it looks, but I do like how it says something instead of a picture (icon). I dont really like how its forced on the lfet side of the action bar by my icon.
Can i just make a 'button' that says options that I can make appear on the right side. In one of my other apps I did this on the right side, but it was just using an icon as a menu. Can you use a text button as a menu?
Try to remove the android:icon attribute from your menu XML :
<item android:id="#+id/my_id"
android:title="#string/my_string"
android:showAsAction="ifRoom|withText" />
Or try to use the Icon Generator from here, chose the Text tab and generate your icons with the provided text.
In your menu.xml, you simply remove the android:icon="#drawable/ic_someicon" entry. This means that the Action Bar entry becomes whatever is in the android:title="#string/some_menu_title" attribute instead; that is, it becomes a button with text rather than a button with an icon.
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 have an android application that I want to add a sub menu for. The background of the application is the default which is black. All of the text on the app is white which I also think is the default. So I added in the sub menu but when I click on the sub menu the background turns to white but the text doesn't turn to black.
Any idea why the default sub menu behavior isn't working correctly? I'm hoping not to have to create styles and all that and the solution will be fairly simple.
Figured this out. This was due to me using titleCondensed instead of just using title. For some reason on sub menus it needs to use title but on the regular menu it works fine. Programming mistake by me.
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.