Android Studio add image on menu - android

I would like to insert an image in the menu background, but in the properties of the menu is not such action. How I do this?
This is the menu code (it's very simple):
menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/MENU_1"
android:title="Gioca"/>
<item
android:id="#+id/MENU_2"
android:title="Esci"/>
</menu>

You need to add this in the xml:
android:icon="#drawable/your_icon_for_menu"

Related

In Navigation Architecture is it possible to replace ActionBar menu completely?

I'm using AndroidX Navigation architecture and want to know is it possible to replace the ActionBar menu completely or not?
In the project, in the Menu directory, there is a home.xml file that contains a menu items:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/homeMainMenu">
<item
android:id="#+id/action_inbox"
android:icon="#drawable/ic_baseline_mail_outline_24"
android:title="#string/action_inbox"
app:showAsAction="ifRoom" />
<item android:icon="#drawable/ic_baseline_more_vert_24"
android:title="#string/app_name"
app:showAsAction="always">
<menu>
<item
android:id="#+id/action_exitapp"
android:icon="#drawable/ic_baseline_exit_to_app_24"
android:title="#string/action_exit"
app:showAsAction="never" />
</menu>
</item>
</menu>
I want to create another menu XML file like mymenu.xml and on the fragment replace it with the home menu. Because of some reason don't want to replace items.
Is it possible? If "Yes" how to handle item click?
If i got your question correct then i guess you want to create different menu for activity and its fragment. You can do that. Please check here
Remember you've to add hasOptionsMenu in fragment onCreate

How to achieve a ripple animation by clicking on a menu item?

I have a toolbar
There is a overflow that displays options in menu
On click of menu item, How to achieve a ripple animation
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menuEventsTodayId"
android:title="#string/menu_events_today" />
<item android:id="#+id/menuUpcomingEventsId"
android:title="#string/menu_upcoming_events" />
<item android:id="#+id/menuSignOutId"
android:title="#string/menu_sign_out" />
</menu>
I tried with:
<item android:id="#+id/menuEventsTodayId"
android:background="?attr/actionBarItemBackground"
android:title="#string/menu_events_today" />
Its not working, How to properly achieve it
Just add the background as ?attr/selectableItemBackground. It will automatically give ripple on Android 5+
You can use following for android version above lollipop:
android:foreground="?attr/selectableItemBackground"
for prelollipop devices, you can use following:
compile 'com.balysv:material-ripple:1.0.2'
You need to define a separate style for your toolbar in the 'values' folder then add the following items to it:
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">#color/ripple_material_dark</item>
Note:- As you can check this Link. ?android:selectableItemBackground is only properties which makes this animation.

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

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>

How to create an OK/Submit button in the ActionBar?

I actually have two questions:
Is there a way to mark a menu item in the ActionBar as the OK/submission button, or is it just a regular item?
Is there a built-in theme for an OK button in the ActionBar (maybe something that looks like a tick-mark?) or must I create my own image file?
I found this icon in Sherlock, it looks like a tick mark and it seems to do the job:
abs__ic_cab_done_holo_light.png
So this is my menu xml (located in res/menu):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/done_item"
android:icon="#drawable/abs__ic_cab_done_holo_light"
android:showAsAction="always"
android:orderInCategory="1"
android:title="#string/done">
</item>
</menu>

Categories

Resources