How can i add custom option menu icon Android - android

i want to add customs icons to my option menu, like that :
How can i do that with custom icons in my menu.xml ?
Or if you know the list of defaults icons, i am interested by that...
Here is my actual menu.xml code :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_settings"
android:title="#string/menu_settings"
android:orderInCategory="100"
android:showAsAction="never" >
</item>
<item android:id="#+id/item1" android:title="Accueil" android:titleCondensed="Accueil" android:icon="#android:drawable/ic_menu_home"></item>
</menu>
Thanks !

Inside of the item tag, use android:icon="#drawable/your_icon". That should work.

Related

How do I make a navigation drawer in the left and menu icon on the right?

I have tried every option of the android:showAsAction, and it didn't work!
I think that maybe I can't get the concept of how to do it.
my app
how I want it
Try something like this.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_cart"
android:icon="#drawable/ic_action_cart"
android:title="Refresh"/>
<item
Your items
</item>
</menu>
http://www.vogella.com/tutorials/AndroidActionBar/article.html

Update font style for Android MenuItem

I got a problem with the android code. I have a Menu with a SubMenu and I want to set the font style to bold for (Sub)MenuItem if it was clicked by the user. So the menu acts like a filter list, where you can select only one filter at the time and the selected MenuItem become bold. I have to do this programatically, benause the categories were generated/added dynamically.
The menu structure looks like this
...
<menu>
<item android:id="#+id/menu_sort_alphabetically" android:title="by name"></item>
<item android:id="#+id/menu_sort_value" android:title="by value"></item>
<item android:id="#+id/menu_sort_category" android:title="by category">
<menu android:id="#+id/menu_category"
android:checkableBehavior="single">
<item android:title="Category 1"></item>
<item android:title="Category 2"></item>
...
</menu>
</item>
</menu>
...
I tried several ways, but haven't found any solution or idea. It would be nice if someone could help me.

Can I show icon in overflow menu of Android Toolbar?

Please take in consideration that I'm refering to the Toolbar Widget(Android L/API 21+)
By overflow menu and icons I mean something like this one :
Something more difficult : Is there any way that the icons appear on the RIGHT side of the text?
create a menu in menu, for example: main_activity_actions.xml
and use this code for the toolbar, try it:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:All4One="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/algo"//some id
android:icon="#drawable/kami_nomi_zu_shiru_sekai3" //add the image
android:title="nose"
All4One:showAsAction="always">
<menu>
<item android:id="#+id/WIFI"//option to display on the menu
android:icon="#drawable/nisekoi1"//this is a option of the submenu
android:title="#string/WIFI"/>
<item android:id="#+id/DATOS"
android:icon="#drawable/nisekoi6" //this one also is a option
android:title="#string/DATOS"/>
<item android:id="#+id/BT"
android:icon="#drawable/sao1"
android:title="#string/BT"/>
<item android:id="#+id/NADA"
android:icon="#drawable/nisekoi6" //the same
android:title="#string/NADA"/>
</menu>
</item>
</menu>

Actionbarsherlock 3 dots

Basically I am inflating a menu
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
globalMenu = menu;
getSupportMenuInflater().inflate(R.layout.menu_refresh, menu);
return super.onPrepareOptionsMenu(menu);
}
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_refresh"
android:showAsAction="never"
android:title="#string/refresh"/>
<item
android:id="#+id/menu_24hours"
android:showAsAction="never"
android:title="#string/twentyfour_hours"/>
<item
android:id="#+id/menu_1week"
android:showAsAction="never"
android:title="#string/one_week"/>
<item
android:id="#+id/menu_1month"
android:showAsAction="never"
android:title="#string/one_month"/>
<item
android:id="#+id/menu_3month"
android:showAsAction="never"
android:title="#string/three_month"/>
<item
android:id="#+id/menu_6month"
android:showAsAction="never"
android:title="#string/six_month"/>
</menu>
whats happening, is that none of them are showing in 3 dots format.In ice cream sandwich you have to click the button menu on hardware, in nexus it shows 3 dots..
i need everywhere to have it as 3 dots, no device uniqueness.
However if i do this in my menu...
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_refresh"
android:showAsAction="always"
android:icon="#drawable/ic_action_refresh_default" />
</menu>
this shows up in actionbardsherlock on top, on all devices. no menu hardware key.
Try creating dummy actionButton which have 3 dots as the icon. This is what I do if I need 3 dots button to be shown on all devices (Especially Samsung devices which have hardware menu keys).
Note that this is actually a hack
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_dummy_overflow"
android:icon="#drawable/ic_action_ic_overflow"
android:showAsAction="always"
android:title="#string/more">
<menu>
<item
android:id="#+id/menu_open_browser"
android:icon="#drawable/ic_action_ic_browser"
android:showAsAction="never"
android:title="#string/opeinInBrowser">
</item>
</menu>
</item>
</menu>
This is something that's decided by the Android OS build that is running. The bad news is that it means you have little control over it. The good news is that it means the user will see the same behaviour on every app on their phone, so they will be expecting it anyway.
You could mimic the behaviour by manually adding an overflow item to your menu and putting your overflow items into a sub-menu of that item. The downside of this is that the number of items you show is fixed. You won't get the benefit of a tablet in landscape mode showing more items in the ActionBar

Android: Pop up Menu on Menu button pressed

I want to have a normal menu button pop up a second menu.
I don't want a listview of options to display, I want a second, standard menu to pop up when I press a button on the menu.
Using openOptionsMenu(); works when you use onCreateOptionsMenu
but it does not work when you use: onPrepareOptionsMenu
Since I want to change the options on the menu dynamically, I need to use onPrepareOptionsMenu.
Thanks
Use a menu group for any menu item that doesn't have an action itself but opens up a second menu. Here's an example of one I did.
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:titleCondensed="Cats" android:title="Cats" android:id="#+id/cats">
<menu>
<group android:id="#+id/catsGroup">
<item android:titleCondensed="Lolz Cats" android:title="Lolz Cats" android:id="#+id/twod"></item>
<item android:titleCondensed="Ugly Cats" android:title="Ugly Cats" android:id="#+id/ref"></item>
<item android:titleCondensed="Dumb Cats" android:title="Dumb Cats" android:id="#+id/vr"></item>
</group>
</menu>
</item>
<item android:titleCondensed="Dogs" android:title="Dogs" android:id="#+id/dogs">
<menu>
<group android:id="#+id/dogsGroup">
<item android:titleCondensed="Awesome Dog" android:title="Awesome Dog" android:id="#+id/pan"></item>
<item android:titleCondensed="Under Dog" android:title="Under Dog" android:id="#+id/zoom"></item>
<item android:titleCondensed="Snoopy" android:title="Snoopy" android:id="#+id/contrast"></item>
<item android:titleCondensed="Scooby Doo" android:title="Scooby Doo" android:id="#+id/page"></item>
<item android:titleCondensed="Pluto" android:title="Pluto" android:id="#+id/rotate"></item>
</group>
</menu>
</item>
</menu>
The first menu items that will show are "Cats" and "Dogs". When you select on of these, their sub items will be shown. Hope this helps.

Categories

Resources