java - Display menus in appbar right -
hi learning material design , have created appbar. when add items main_menu displays in drop down, want display new icon before settings icon in app bar.
my app
1) want add icon next settings icon. shows in dropdown box when click on settings icon.
main menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".mainactivity"> <item android:id="@+id/action_settings" android:title="@string/action_settings" android:orderincategory="100" app:showasaction="never" /> <item android:id="@+id/favorite" android:title="@string/favourite" android:orderincategory="200" android:showasaction="always" android:icon="@drawable/ic_favorite_white_24dp" /> </menu>
mainactivity.java
public class mainactivity extends actionbaractivity { private toolbar toolbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar = (toolbar) findviewbyid(r.id.app_bar); setsupportactionbar(toolbar); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } if (id == r.id.favorite){ return true; } return super.onoptionsitemselected(item); } }
try code
<item android:id="@+id/favorite" android:title="@string/favourite" android:showasaction="always" android:icon="@drawable/ic_favorite_white_24dp" /> <item android:id="@+id/action_overflow" android:orderincategory="100" android:title="@string/action_settings" android:icon="@mipmap/options" app:showasaction="always"> <menu> <item android:id="@+id/action_my_music" app:showasaction="ifroom" android:title="my music" /> <item android:id="@+id/action_friends" app:showasaction="ifroom" android:title="friend`s music" /> </menu> </item>
Comments
Post a Comment