am tying to hide my action bar in runtime when i switch from tab2 to tab1 or tab3 but its leaving a blank space
my Activity: (with a TabLayout and 3 fragments )
switched to another tab , action bar is hidden now but there's a Blank space :
am using actionBar.hide
/ actionBar.show
, any clue how to properly remove this extra space ??? if what am trying to achieve is not possible then please guide me to any alternative way
Codes:
ActionBar actionBar;
........
........
actionBar = getSupportActionBar();
........
........
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab == tab2){
actionBar.show();
}else {
actionBar.hide();
}};
Added Xml Codes:
MainActivity which includes content_main
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="MainActivity"
android:animateLayoutChanges="true">
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:animateLayoutChanges="true">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e4e4e4"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fillViewport="false"
android:clickable="false" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tabs"/>
</RelativeLayout>