fragment 动态改版menu ,非Activity中
来源:互联网 发布:淘宝炫富图片大全 编辑:程序博客网 时间:2024/05/16 10:15
fragment 中布局加入toolbar,上层Activity中无toolbar
1、复写onPrepareOptionsMenu方法
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.clear();//先清除已经建好的menu
MenuInflater inflater = getActivity().getMenuInflater();
//根据各种条件,重新设置menu
if (isDeleteIconOnActionBar){
inflater.inflate(R.menu.delete_action, menu);
}else if(isRefreshIconOnActionBar){
inflater.inflate(R.menu.delete_refresh_action, menu);
}else{
inflater.inflate(R.menu.main_activity_actions, menu);
}
super.onPrepareOptionsMenu(menu);
}
2、在需要修改menu的地方调用
getActivity().supportInvalidateOptionsMenu();
特别说明
// 此方法可以动态改变ActionBar的菜单图标// getActivity().getWindow().invalidatePanelMenu(// Window.FEATURE_OPTIONS_PANEL);//此方法对frament下的toolbar不生效
阅读全文
0 0
- fragment 动态改版menu ,非Activity中
- Activity中动态添加Fragment.
- fragment中使用menu
- 在Activity中静态、动态添加Fragment
- Android同一Activity中不同Fragment设置不同的menu(ViewPager+Fragment)
- Fragment——向Activity中动态加载Fragment
- menu中 跳转Activity
- Activity中使用Menu
- Activity中使用Menu
- Activity动态增加Fragment
- Activity动态添加fragment
- Activity动态添加Fragment
- Fragment中menu菜单注意事项
- 在Fragment中使用Menu
- Fragment中menu菜单注意事项
- Fragment中menu菜单注意事项
- Android 在Fragment或activity中显示与隐藏Menu的菜单
- activity中动态嵌套使用fragment的方法
- imgproc模块--图像平滑处理
- VS2005编译Openssl-1.1.0f
- 枚举+并查集
- Andorid中的AIDL(三)
- LeetCode 345 Reverse Vowels of a String
- fragment 动态改版menu ,非Activity中
- Tomcat服务器报错: Could not publish to the server. java.lang.NullPointerException
- 透明控件点击事件
- LeetCode 387 First Unique Character in a String
- 初接触Directdraw
- mybatis useGeneratedKeys = "true"
- 71-75.个人练习。
- LeetCode 541 reverse string 2
- spring读写excel文件的时候,return语句或者异常信息写到了文件里面