Sherlock Actionbar change menu background color

风格不统一 提交于 2019-12-11 11:45:38

问题


I need to change the background of menu items only. When I tried with actionBarItemBackground, it changes the background of application logo [As u can see in the attachment] also. Any help or link will be appreciated.


回答1:


You can use a custom layout for your actionbar item like so:

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
         <item android:id="@id/item_text"
            android:showAsAction="always"
            android:actionLayout="@layout/action_text"/>
    </menu>

This is styleable as you wish. Another possibility would be adding only the ID (item_text in the example) and set the background like so:

 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
      MenuItem item = menu.findItem(R.id.item_text);
      item.getActionView().setBackgroundDrawable(new ColorDrawable(/* your color */));

      return super.onPrepareOptionsMenu(menu);
 }


来源:https://stackoverflow.com/questions/18871138/sherlock-actionbar-change-menu-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!