How To Remove Gap Between Toolbar And Layout Underneath
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:
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:
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"