选项​​菜单中默认的灰色边框去除边框、选项、灰色、菜单中

2023-09-12 08:21:34 作者:全幼儿园最可爱

在我的应用程序,我有选择的菜单我尝试定制它,我做到了由它指的风格,

我需要的是要么拆除默认的灰色边框选项菜单或定制,以另一种颜色。

任何意见将AP preciated。

,如下所示:

我的code:

 公共布尔onCreateOptionsMenu(android.view.Menu菜单){

   MenuInflater充气= getMenuInflater();
   inflater.inflate(R.menu.cool_menu,菜单);

   getLayoutInflater()。setFactory(新厂(){
   公共查看onCreateView(字符串名称,上下文的背景下,
   AttributeSet中的ATTRS){

如果(名称.equalsIgnoreCase(com.android.internal.view.menu.IconMenuItemView)){
尝试 {

  LayoutInflater李= LayoutInflater.from(上下文);
  最终的视图中查看= li.createView(姓名,空,ATTRS);

  新的处理程序()。后(新的Runnable(){
  公共无效的run(){

  查看.setBackgroundResource(R.drawable.border1);

  ((TextView中)查看).setTextSize(20);

  ((TextView中)查看).setTextColor(Color.RED);
                 }
             });
   返回查看; }
   赶上(InflateException E){}
   赶上(ClassNotFoundException异常E){}
        }
   返回null; }
      });
   返回super.onCreateOptionsMenu(菜单); }
 

解决方案

您是否尝试过在看这个问题? Change选项​​菜单的背景颜色你应该能够使用大多数在那里的答案能帮助你!

in my app i have option menu i try to customize it , i did it by refer it to style ,

what i need is either removal of default gray border around option menu or customize it to another color .

any advice will be appreciated .

as shown below :

My code :

 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);   }

解决方案

Have you tried looking at this question? Change the background color of the options menu you should be able to use most of the answers on there to help you!

 
精彩推荐
图片推荐