大众信息网

android optionmenu 怎么定义背景颜色色

关注:277  答案:2  手机版
解决时间 2021-01-28 04:43
android optionmenu 怎么定义背景颜色色
最佳答案
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;
     }
    });
 } 如果2.3以上修改没效果,把 getLayoutInflater()改为 (LayoutInflater) context  .getSystemService(Context.LAYOUT_INFLATER_SERVICE)
全部回答
android旋钮背景颜色 android按钮背景颜色 默认情况下,button使用android系统提供的默认背景。因此在不同平台上或者设备上,button显示的风格也不相同。android支持修改button默认的显示风格,可通过drawable状态列表替换默认的背景
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!