改变Android中menu菜单的背景色

 (2011-07-16 21:20:06)
标签: 

it

分类: 技术学习

protected void setMenuBackGround() {   getLayoutInflater().setFactory(     new android.view.LayoutInflater.Factory() {

     @Override      public View onCreateView(String name, Context context,        AttributeSet attrs) {       // TODO Auto-generated method stub       // 指定自定义inflater的对象       if (name         .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {        try {         LayoutInflater inflater = getLayoutInflater();         final View view = inflater.createView(name,           null, attrs);         new Handler().post(new Runnable() {          public void run() {           view             .setBackgroundResource(R.drawable.application_background_static);          }         });         return view;        } catch (InflateException e) {         e.printStackTrace();        } catch (ClassNotFoundException e) {         e.printStackTrace();        }       }       return null;      }     });  }

posted on 2012-12-24 16:45  zhengbeibei  阅读(2904)  评论(0编辑  收藏  举报