Android(安卓)修改Menu背景
16lz
2022-07-23
public void setMenuBackground(Context context, Menu menu) {((Activity) context).getLayoutInflater().setFactory(new Factory() {@Overridepublic View onCreateView(String name, Context context,AttributeSet attrs) {if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {try {LayoutInflater f = ((Activity) context).getLayoutInflater();final View view = f.createView(name, null, attrs);// 尝试创建我们自己布局new Handler().post(new Runnable() {public void run() {view.setBackgroundResource(R.drawable.menu_bg);// 设置背景为我们自定义的图片,替换cwj_bg文件即可}});return view;} catch (Exception e) {}}return null;}});}
更多相关文章
- android 系统中静音后使得音量减键不能解除静音
- AndroidStudio使用ViewPagerIndicator
- android中字符替换成表情
- Ubuntu上安装和使用Android(安卓)Studio
- 自定义SeekBar主题
- Android(安卓)启动时闪一下黑屏问题的解决办法
- Android(安卓)Studio更改SDK或者JDK路径
- android 设置linelayout让按钮自动适应屏大小
- Android(安卓)fragment在xml中使用没添加ID