0

In my android application, I want to display tabs under the action bar and action bar should not have the home icon.

Below is my code.

 // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getSupportActionBar();
    View actionbar1 = LayoutInflater.from(this).inflate(R.layout.header,
null);
    actionBar.setCustomView(actionbar1);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

    mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); 
    viewPager.setAdapter(mAdapter);        
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

and the output is in the below screen. I want the action bar to be top of the page and below that the tabs should come.

enter image description here

Please help me how to solve the above issue. I'm looking forward for your responses.

Thanks

adneal
  • 30,484
  • 10
  • 122
  • 151
user2636874
  • 889
  • 4
  • 15
  • 36

1 Answers1

2

I had the same problem yesterday on zenfone6, and then I found a lot of information about this issue then I fixed it now.

Here is my solution:

Set actionBar.setDisplayShowHomeEnabled(true)

This will make your tab bar go below the main action bar because the function of the up indicator appearing at the left side of the action bar as up navigation is enabled now.

(If you want to know more about what is up navigation, you can check this http://www.grokkingandroid.com/actionbarsherlock-up-navigation/)

Now, after typing the code above, you will find that there is padding left on the left side of the action bar because we just enabled the up indicator. I solve this problem by forcing the drawable used as up indicator in res/values-v14/styles.xml to null

Like this:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 14 theme customizations can go here. -->
    <item name="android:homeAsUpIndicator">@null</item>
</style>

I found this solution from here: remove padding around action bar left icon on Android 4.0+

Community
  • 1
  • 1
luchichi
  • 21
  • 4
  • Please provide some description and detail about the method. So, your answer can look more informative and it can help other users also. – Shell Aug 07 '14 at 05:41