Skip to content Skip to sidebar Skip to footer

How To Display Settings Menu On Click Of Settings Icon?

Settings menu is created in activity_settingsmenu.xml . Settings icon is in activity_settingsicon.xml . How to link both the activities so that on clicking settings icon, the set

Solution 1:

create menu folder in res.Create xml for e.g menu_main.xml under menu folder.

<menuxmlns: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="in.nfnlabs.stormit.Parent"><itemandroid:id="@+id/action_settings"android:orderInCategory="100"android:title="@string/action_settings"app:showAsAction="never" /></menu>

If u want to add icon, use this:

<itemandroid:id="@+id/action_settings"android:title="@string/action_settings"android:icon="@drawable/bookmark"android:orderInCategory="100"app:showAsAction="always" />

In your activity class inflate the menu like below:

@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.addnew, menu);
    returntrue;
}

If you want to perform actions in menu this can be achieved by onOptionsItemSelected

publicbooleanonOptionsItemSelected(MenuItem item) {
    inti= item.getItemId();
    if(i==R.id.action_settings) {
        Toast.makeText(getApplicationContext(), "Bookmark", Toast.LENGTH_SHORT).show();
    }
}

Post a Comment for "How To Display Settings Menu On Click Of Settings Icon?"