[英]Sherlock Actionbar change menu background color
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.
当我尝试使用actionBarItemBackground时,它也会更改应用程序徽标的背景[如您在附件中所见]。 Any help or link will be appreciated.
任何帮助或链接将不胜感激。
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:
另一种可能性是仅添加ID(示例中为item_text)并像这样设置背景:
@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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.