Displaying icon for menu items of Action Bar in Honeycomb android 3.0

后端 未结 3 1311
余生分开走
余生分开走 2020-12-01 20:09

hi
I am developing an android application using Honeycomb android 3.0 . I am tryig to display a menu in Action Bar . The menu has an icon and tiltle. When we click the

3条回答
  •  有刺的猬
    2020-12-01 20:37

    Actually, there is a way to put icons next to the texts for the menu items:

    final MenuItem menuItem=...
    final ImageSpan imageSpan=new ImageSpan(this,R.drawable.ic_stat_app_icon);
    final CharSequence title=" "+menuItem.getTitle();
    final SpannableString spannableString=new SpannableString(title);
    spannableString.setSpan(imageSpan,0,1,0);
    menuItem.setTitle(spannableString);
    

    This will put an icon at the beginning of the menu item, right before its original text.

    BTW, this will also work on PopupMenu.

提交回复
热议问题