Skip to content Skip to sidebar Skip to footer

How To Remove Gap Between Toolbar And Layout Underneath

Tried implementing a toolbar for my layout but a gap keeps appearing underneath it. What is the correct way to eliminated that gap? I believe android:fitsSystemWindows='false' or a

Solution 1:

Short answer

Delete this line from your layout:

<include layout="@layout/my_toolbar"/>

Long answer

I took your layout and put it in my project, along with your SlidingTab... classes. My MainActivity.java was quite simple; I just populated the ViewPager with an adapter that created a handful of "hello world" fragments.

publicclassMainActivityextendsAppCompatActivity {

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ViewPagerpager= (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(newMyPagerAdapter(getSupportFragmentManager()));

        SlidingTabLayout_DarkTabStriptabs= (SlidingTabLayout_DarkTabStrip) findViewById(R.id.tabs);
        tabs.setViewPager(pager);
    }

    privatestaticclassMyPagerAdapterextendsFragmentPagerAdapter {

        publicMyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @OverridepublicintgetCount() {
            return5;
        }

        @Overridepublic Fragment getItem(int position) {
            returnnewMyFragment();
        }

        @Overridepublic CharSequence getPageTitle(int position) {
            return"Item: " + position;
        }
    }
}

This is what I saw when I ran it:

enter image description here

That empty space between the actionbar and the tab strip is the <android.support.v7.widget.Toolbar> included in the layout. Essentially, I have two toolbars: the system actionbar and the Toolbar in the layout... but the second one isn't populated.

I assume you're setting your navigation icon, title, and subtitle to the system actionbar. If I add these lines to my onCreate():

getSupportActionBar().setTitle("Toolbar");
    getSupportActionBar().setSubtitle("Toolbars are awesome");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

I now see:

enter image description here

That's exactly what you have in your screenshot. So just delete the <include> tag.

Post a Comment for "How To Remove Gap Between Toolbar And Layout Underneath"