相关疑难解决方法(0)

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

我试图创建一个没有应用程序徽标/文本的动作栏,并且使用集中的图片,我知道可以使用自定义视图,这是我的代码:

protected void initActionBar()
{
    RelativeLayout custom = new RelativeLayout(getApplicationContext());
    ActionBar.LayoutParams params = new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    custom.setLayoutParams(params); 

    custom.setGravity(Gravity.CENTER);
    custom.setBackgroundDrawable(getResources().getDrawable(R.drawable.background_grad_grey_rounded));

    ImageView image =new ImageView(getApplicationContext());
    image.setBackgroundResource(R.drawable.ic_launcher); 
    custom.addView(image);

    ab = getSupportActionBar();


    ab.setDisplayShowCustomEnabled(true);
    ab.setCustomView(custom);
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    tab_connect = ab.newTab();
    tab_connect.setText("CONNECT");
    tab_connect.setTabListener(this);

    tab_discover = ab.newTab();
    tab_discover.setText("DISCOVER");
    tab_discover.setTabListener(this);

    tab_simplify= ab.newTab();
    tab_simplify.setText("SIMPLIFY");
    tab_simplify.setTabListener(this);

    ab.addTab(tab_simplify);
    ab.addTab(tab_discover);
    ab.addTab(tab_connect);

    ab.setDisplayShowTitleEnabled(false);
    ab.setDisplayShowHomeEnabled(false);

}
Run Code Online (Sandbox Code Playgroud)

但是,当我隐藏徽标时,操作栏会移动到我的标签下方,如下所示:

屏幕截图

但如果我设置了ab.setDisplayShowHomeEnabled(true),则操作栏会出现在它的正确位置(但带有我不想要的徽标):

在此输入图像描述

我究竟做错了什么?

tabs android actionbarsherlock android-actionbar

20
推荐指数
3
解决办法
8843
查看次数