Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

java - Option menu default gray border removal

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 :

enter image description here

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);   }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...