-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. Android工作室项目中的菜单栏
- 4. wxPython并在菜单栏中选择时添加选项菜单
- 5. 选项菜单不工作
- 6. Android菜单选项不工作
- 7. Android - 选项菜单不会工作
- 8. Android:块选项菜单,而折叠工具栏
- 9. 在Android中添加选项菜单
- 10. Android工具栏子菜单中UNchecked菜单项的颜色
- 11. 工具栏菜单选项没有在fragmnets中显示
- 12. 向XPEditor中的CKEditor默认工具栏添加菜单项
- 13. 在joomla 1.5组件中添加工具栏菜单项。
- 14. 在Firefox中添加工具栏按钮和菜单项
- 15. 无法更改Android工具栏上菜单项的颜色选项
- 16. 从Android工作室底部工具栏运行选项卡已经消失
- 17. 选项菜单操作栏
- 18. 如何将单个菜单项添加到android的工具栏中?
- 19. Android工作室:如何使用ViewPager添加选项卡
- 20. Android工具栏选项卡导航
- 21. Android操作栏 - 禁用选项菜单
- 22. Android菜单选项卡式操作栏
- 23. Android:选项菜单+操作栏
- 24. 如果没有选项菜单,工具栏主页按钮不起作用
- 25. 更改选定的工具栏菜单项背景颜色
- 26. 工具栏上的复杂菜单项
- 27. jEasyUI,选项卡中的工具栏
- 28. 将选项卡添加到ExtJS中的现有工具栏
- 29. 如何在XML布局中添加选项卡和工具栏
- 30. Android - 作为选项卡的菜单项
的[自定义主工具栏中的Android Studio中的选项菜单(http://stackoverflow.com/questions/可能的复制36442116 /自定义选项菜单的主工具栏在Android工作室) – Ironman
嗨。我确实检查了这个链接。这与我打算做的有点不同。尽管我找到了解决方案。谢谢无论如何.. :) – Mehul