Action bar being shown below its tabs

依然范特西╮ 提交于 2020-01-21 11:29:10

问题


When i set these attributes:

    actionBar = getSupportActionBar();

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("Title");
    actionBar.setLogo(null);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

The ActionBar is below its Tabs.

But if i comment this Like:

actionBar.setDisplayShowHomeEnabled(false);

It works fine. But the reason i want it to be false is, to avoid the appIcon being shown.

Thank You


回答1:


I googled this problem and found this thread on gitub: https://github.com/JakeWharton/ActionBarSherlock/issues/327

You can read the thread, but the conclusion is:

Hi. Just found a simple workaround.

Use the following in your onCreate method :
View homeIcon = findViewById(android.R.id.home);
((View) homeIcon.getParent()).setVisibility(View.GONE);
this collapses the home button completely.

PS : i'm using standard ActionBar but this should work the same

I hope this helps you out,
Daniel.




回答2:


i used this, and it's work on me

    ActionBar ab = getSupportActionBar();
    ab.setDisplayShowHomeEnabled(true);
    ab.setDisplayHomeAsUpEnabled(false);
    ab.setHomeButtonEnabled(false);
    ab.setLogo(null);

    View homeIcon = findViewById(
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? 
            android.R.id.home : R.id.abs__home);
    ((View) homeIcon.getParent()).setVisibility(View.GONE);
    ((View) homeIcon).setVisibility(View.GONE);

    ab.setDisplayShowTitleEnabled(false);



回答3:


All post above collapsing the home icon but leaving a blank space. For avoiding that you need to set the logo size to zero . Below added my code snippet.it may help for others who struggle with same problem.thanks

       actionBar.setLogo(new ColorDrawable(Color.TRANSPARENT));

      View homeIcon = findViewById(
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? 
                android.R.id.home : R.id.abs__home);
        ((View) homeIcon.getParent()).setLayoutParams(new LayoutParams(0, 0));
        ((View) homeIcon).setVisibility(View.GONE);


来源:https://stackoverflow.com/questions/13760325/action-bar-being-shown-below-its-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!