2

I'm having this strange behavior with the action ActionBar Tabs showing above the ActionBar. This happens to be happening when I am setting a custom view for the ActionBar.I'm implementing the Done-Discard pattern using Roman Nurik's example here

This is happening due to the masking of ActionBar.DISPLAY_SHOW_HOME in setDisplayOptions()

final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
                    | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

The screen looks like this: enter image description here

But when I dont mask the ActionBar.DISPLAY_SHOW_HOME it works fine but the App Logo is displayed. like this.

enter image description here

This seems to be a bug.Please suggest a fix.I don't want the logo to be displayed.

4

2 回答 2

2

这里的解决方案:

ActionBarSherlock - 使用自定义视图显示在操作栏上方的选项卡

在这里:https ://github.com/JakeWharton/ActionBarSherlock/issues/327

这对我来说似乎有点 hacky,但这是解决方法:在你的 onCreate 中添加这段代码并隐藏主页图标。现在 ActionBar 和 Tabs 可以按预期工作。

请记住不要禁用/屏蔽 ActionBar.setDisplayOptions() 中的 DISPLAY_HOME_HOME。如果您屏蔽/禁用它,这将不起作用。

View homeIcon = findViewById(android.R.id.home);
        ((View) homeIcon.getParent()).setVisibility(View.GONE);
于 2012-12-04T12:19:54.623 回答
1

首先将操作栏的“DisplayShowHomeEnabled”属性设置为“true”:

actionBar.setDisplayShowHomeEnabled(true);

接着:

View homeIcon = findViewById(android.R.id.home);
    ((View) homeIcon.getParent()).setVisibility(View.GONE);
    ((View) homeIcon).setVisibility(View.GONE);

我希望它有帮助:)

于 2015-05-15T06:59:04.483 回答