选项菜单默认灰色边框删除

时间:2012-05-09 17:50:40

标签: java android

在我的应用程序中我有选项菜单我尝试自定义它,我通过将其引用到样式

来实现

我需要的是删除选项菜单周围的默认灰色边框或将其自定义为另一种颜色。

任何建议将不胜感激。

如下图所示:

enter image description here

我的代码:

 public boolean onCreateOptionsMenu(android.view.Menu menu) {

   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.cool_menu, menu);

   getLayoutInflater().setFactory(new Factory() {
   public View onCreateView(String name, Context context,
   AttributeSet attrs) {

if (name .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try {

  LayoutInflater li = LayoutInflater.from(context);
  final View view = li.createView(name, null, attrs);

  new Handler().post(new Runnable() {
  public void run() {

  view .setBackgroundResource(R.drawable.border1);

  ((TextView) view).setTextSize(20); 

  ((TextView) view).setTextColor(Color.RED);
                 }
             });
   return view;  }
   catch (InflateException e) {}
   catch (ClassNotFoundException e) {}
        }
   return null; }
      });
   return super.onCreateOptionsMenu(menu);   }

1 个答案:

答案 0 :(得分:0)

你试过看过这个问题吗? How to change the background color of the options menu?你应该能够使用那里的大多数答案来帮助你!

相关问题