Adding Custom Menu In Messege Activity In Android
I want to add my custom menu in the messege activity. While I am typing a messege, I want to show additional menu 'Add contact' which will add contact information of another contac
Solution 1:
You would want to override these methods in your activity:
@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
MenuInflaterinflater= getMenuInflater();
inflater.inflate(R.menu.my_custom_menu, menu);
returnsuper.onCreateOptionsMenu(menu);
}
@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menuAddContact:
startActivity(newIntent(ThisActivity.this,
AddContact.class));
break;
}
returnsuper.onOptionsItemSelected(item);
}
Then you need a custom menu xml file
<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:id="@+id/menuAddContact"android:title="Add Contact" /></menu>
See more here: http://developer.android.com/guide/topics/ui/menus.html
Post a Comment for "Adding Custom Menu In Messege Activity In Android"