简体   繁体   English

Sherlock动作栏的菜单项背景

[英]Sherlock action bar's menu item background

i am having issue with rendering custom view in Sherlock action bar. 我遇到了在Sherlock操作栏中渲染自定义视图的问题。 what happen is i've successfully set the custom view in action bar designed to set the Title textview in center, but when i set the other menu items like refresh then it's background appears with black color. 发生了什么事情我已成功设置自定义视图在操作栏中设计为将标题文本视图设置在中心,但是当我设置其他菜单项如刷新时,它的背景显示为黑色。 same things happens with home button. 主页按钮也会发生同样的事情。 please go through the following snapshot. 请仔细阅读以下快照。

自定义Sherlock动作栏

as you can see in this image when i set home button visible or set the refresh menu item it should not displayed like this with black background. 正如您在此图像中看到的那样,当我将主页按钮设置为可见或设置刷新菜单项时,它不应显示为黑色背景。

in my Activity screen 在我的活动屏幕中

protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.menu_activity);
   .... 
   View customNav = LayoutInflater.from(this).inflate(R.layout.custom_navigation, null);
   TextView textView = (TextView)customNav.findViewById(R.id.screen_title);
   textView.setText("Category");
   getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
   getSupportActionBar().setCustomView(customNav);
   getSupportActionBar().setDisplayHomeAsUpEnabled(true);
   getSupportActionBar().setDisplayShowHomeEnabled(true);   
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0,Constants.REFRESH_ITEM_ID,0,Constants.LABEL_REFRESH)
        .setIcon(R.drawable.ic_refresh)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    return true;
}

I've tried a lot but fail to fix it.Please help me. 我已经尝试了很多,但未能解决它。请帮助我。 Thanks in Advance. 提前致谢。

It seems you use Theme.Sherlock.Dark in manifest file for whole application or this activity. 您似乎在清单文件中使用Theme.Sherlock.Dark进行整个应用程序或此活动。 It is normal behavior of ActionBar -- it is defined by style, but your custom view-element has is own backround, text style, etc... From setCustomView() javadoc: 这是ActionBar的正常行为 - 它由样式定义,但您的自定义视图元素具有自己的背景,文本样式等...来自setCustomView()javadoc:

Custom navigation views appear between the application icon and any action buttons and may use any space available there. 应用程序图标和任何操作按钮之间会出现自定义导航视图,并可能使用此处可用的任何空间

This method just add new view to bar, but doesn't set 'view for whole bar'. 此方法只是向条形图添加新视图,但不设置“整条视图”。

Take a look at http://jgilfelt.github.com/android-actionbarstylegenerator -- this is a style generator for action bar. 看一下http://jgilfelt.github.com/android-actionbarstylegenerator - 这是一个动作栏的样式生成器。 Pay attention to the toggle button "Style compatibility". 注意切换按钮“样式兼容性”。

I have found the solution of this not exactly the way i wanted but the other way. 我已经找到了解决方案,这不是我想要的方式,而是另一种方式。 actually i've created the images with centred screen title for various screens and setting it as the action bar background rather than creating a custom view and SherlockActionBar is flexible enough to hide the default title displayed on the upper-left corner. 实际上我已经为各种屏幕创建了带有居中屏幕标题的图像,并将其设置为操作栏背景而不是创建自定义视图,而SherlockActionBar足够灵活,可以隐藏左上角显示的默认标题。 all i have done is. 我所做的就是。

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar()
            .setBackgroundDrawable(getResources().getDrawable(R.drawable.menu_head));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM