ActionBarSherlock - Tabs appearing ABOVE actionbar with custom view

前端 未结 7 1877
春和景丽
春和景丽 2020-12-13 14:33

I Am trying to create an actionbar without the app logo/text, and with a centralised picture, and i know it is possible with a custom view, here is my code:

         


        
相关标签:
7条回答
  • 2020-12-13 15:08

    this works great too! (read the bugreport comments ;))

    actionBar.setLogo(new ColorDrawable(Color.TRANSPARENT));
    
    0 讨论(0)
  • 2020-12-13 15:09

    I used this

    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);
    
    0 讨论(0)
  • 2020-12-13 15:11

    Here's 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

    Or

    if you want to support in Sherlock Actionbar to than you have to use this

    actionBar.setLogo(null); // forgot why this one but it helped
    
    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);
    
    actionBar.setDisplayShowTitleEnabled(false);
    
    0 讨论(0)
  • 2020-12-13 15:14

    It is worth noting that the selected answer will only work with the native ActionBar because the element android.R.id.home doesn't exist on pre-hc. That is, on pre-hc devices, you will get an NPE.

    Since you are using ActionBarSherlock, I'm assuming you want to support pre-hc devices so you should use the correct id based on the platform version. ABS will expose the equivalent of android.R.id.home via R.id.abs__home for its implementation of the ActionBar.

    So, we can tweak the suggested workaround as:

    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);
    
    0 讨论(0)
  • 2020-12-13 15:16

    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 LinearLayout.LayoutParams(0, 0));
            ((View) homeIcon).setVisibility(View.GONE);
    
    0 讨论(0)
  • 2020-12-13 15:26

    just remove DISPLAY_SHOW_HOME flag from your actionBar.setDisplayOptions() method.

    0 讨论(0)
提交回复
热议问题