开发者

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 开发者_Python百科contact in this messege body.

Please help

Thanks in advance


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜