View

Monday, 1 August 2011

How to use Menu Option in Android?

Its a very simple way to use menu option in android, just only four line to write it. first u have to  create new folder and name as menu
example res/menu/sample.xml.
give some options what u want ,Here i gave file,open,save and edit

<?
<
xml version="1.0" encoding="utf-8"?>menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/file" android:title="@string/file" />
<item android:id="@+id/open" android:title="@string/open"/> <item android:id="@+id/save" android:title="@string/save" />
<item android:id="@+id/edit" android:title="@string/edit"/> </menu>
after that we have to set a values in strings.xml
example:values/strings.xml
<?
<
xml version="1.0" encoding="utf-8"?>resources>
<string name="hello">Hello World, MenuScreen!</string>
<string name="app_name">SampleMenu</string>
<string name="file">File</string>
<string name="open">Open</string>
<string name="save">Save</string>
</
<string name="edit">Edit</string>resources>
now you have to write a code to show the menu options.
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.sample, menu);         
        return true;
    }
Result is:

1 comment:

  1. blogwalking need friends list folow me i will folow you back :) natamp3

    ReplyDelete