福尔摩斯动作条改变菜单的背景颜色福尔摩斯、菜单、颜色、背景

2023-09-12 03:19:49 作者:♡♡╱微笑

我需要改变的只是菜单项的背景。当我试图用actionBarItemBackground,它改变了应用程序标识的背景为u可以在附件中看到]也。任何帮助或链接将AP preciated。

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.

推荐答案

您可以使用自定义布局的动作条项目像这样:

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>

,你想这是设置样式。另一种可能性是只添加了ID(item_text中的例子),并设置背景像这样:

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