覆写onCreateOptionsMenu方法
Java代码
@Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.home_timeline_menu, menu);
return true;
}
res的menu文件夹下新建一个文件,内容如下:
Java代码
1. <?xml version="1.0" encoding="utf-8"?>
2. "http://schemas.android.com/apk/res/android">
3. "@+id/menu_settings" android:title="设置" android:icon="@drawable/menu_settings" android:alphabeticShortcut="s"/>
4. "@+id/menu_official" android:title="官方微博" android:icon="@drawable/menu_official" android:alphabeticShortcut="d"/>
5. "@+id/menu_feedback" android:title="意见反馈" android:icon="@drawable/menu_feedback" android:alphabeticShortcut="b"/>
6. "@+id/menu_account" android:title="账号管理" android:icon="@drawable/menu_account" android:alphabeticShortcut="h"/>
7. "@+id/menu_about" android:title="关于" android:icon="@drawable/menu_about" android:alphabeticShortcut="f"/>
8. "@+id/menu_quit" android:title="退出" android:icon="@drawable/menu_quit" android:alphabeticShortcut="n"/>
9. </menu>