Navnath
Navnath

Reputation: 11

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 contact in this messege body.

Please help

Thanks in advance

Upvotes: 1

Views: 5194

Answers (1)

Thomas Dignan
Thomas Dignan

Reputation: 7102

You would want to override these methods in your activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.my_custom_menu, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
    case R.id.menuAddContact:
        startActivity(new Intent(ThisActivity.this,
                AddContact.class));
        break;
    }
    return super.onOptionsItemSelected(item);
}

Then you need a custom menu xml file

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menuAddContact" android:title="Add Contact" />
</menu>

See more here: http://developer.android.com/guide/topics/ui/menus.html

Upvotes: 4

Related Questions