Menu In Android Sample
Create menu_custom.xml inside res/menu folder
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
item
android:id
=
"@+id/first"
android:icon
=
"@drawable/icon1" //if u want image
android:title
=
"First"
/>
<
item
android:id
=
"@+id/second"
android:icon
=
"@drawable/icon2"
android:title
=
"Second"
/>
</
menu
>
Inside Your Activity
Override On
onCreateOptionsMenu and onOptionsItemSelected methods of Activity Class
@Override
public
boolean
onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_custom, menu);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected(MenuItem item) {
switch
(item.getItemId()) {
case
R.id.first:
// Action You want to do on click of First
return
true
;
case
R.id.second:
// Action You want to do on click of First
return
true
;
default
:
return
super
.onOptionsItemSelected(item);
}
}
No comments:
Post a Comment