-1
A
回答
-1
-1
首先,你需要在menu_main.xml添加项(RES>菜单)文件等。
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="in.amzbizsol.vts.MainActivity">
<item
android:id="@+id/action_changepassword"
android:orderInCategory="1"
android:title="Change Password"
app:showAsAction="never" />
<item
android:id="@+id/action_logout"
android:orderInCategory="2"
android:title="Logout"
app:showAsAction="never" />
然后在MainActivity创造这样
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_changepassword) {
Intent intent=new Intent(getApplicationContext(),ChangePassword.class);
startActivity(intent);
return true;
}else if(id==R.id.action_logout){
finish();
}
return true;
}
return super.onOptionsItemSelected(item);
}
+0
解决方案也是重复的问题http://stackoverflow.com/questions/36442116/customize-the-option-menu-of-main-toolbar-in-android-studio –
+0
严重?? @KapilRajput我花了我的时间自己写这段代码,它看起来很像。我知道你不能欣赏,但至少在指出前阅读答案。 – Akash
相关问题
- 1. Android工具栏中的自定义选项菜单
- 2. Android工作室项目中的菜单栏
- 3. wxPython并在菜单栏中选择时添加选项菜单
- 4. 选项菜单不工作
- 5. Android菜单选项不工作
- 6. Android - 选项菜单不会工作
- 7. Android:块选项菜单,而折叠工具栏
- 8. 在Android中添加选项菜单
- 9. Android工具栏子菜单中UNchecked菜单项的颜色
- 10. 工具栏菜单选项没有在fragmnets中显示
- 11. 在joomla 1.5组件中添加工具栏菜单项。
- 12. 无法更改Android工具栏上菜单项的颜色选项
- 13. 选项菜单操作栏
- 14. Android操作栏 - 禁用选项菜单
- 15. Android工具栏选项卡导航
- 16. 更改选定的工具栏菜单项背景颜色
- 17. 工具栏上的复杂菜单项
- 18. 将选项卡添加到ExtJS中的现有工具栏
- 19. 如何在XML布局中添加选项卡和工具栏
- 20. 的Android,在工具栏的布局位置菜单项
- 21. Android - 作为选项卡的菜单项
- 22. FloatingAction菜单按钮在单击选项不工作在android
- 23. CkEditor工具栏组选项下拉菜单
- 24. 使用自定义操作栏/工具栏视图创建选项菜单
- 25. Magento添加按工具栏上的畅销书选项排序
- 26. 添加工具栏项目上默认的工具栏
- 27. 添加工具栏项目或按钮DetailViewController工具栏的iPad
- 28. 如何将上下文菜单项添加到工具栏?
- 29. 没有BWToolkit的首选项工具栏
- 30. Android Webview:为什么不刷新在选项菜单中工作?
的[自定义主工具栏中的Android Studio中的选项菜单(http://stackoverflow.com/questions/可能的复制36442116 /自定义选项菜单的主工具栏在Android工作室) – Ironman
嗨。我确实检查了这个链接。这与我打算做的有点不同。尽管我找到了解决方案。谢谢无论如何.. :) – Mehul