remy boys
remy boys

Reputation: 2958

Action bar is not hiding completely

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 )

enter image description here

switched to another tab , action bar is hidden now but there's a Blank space :

enter image description here

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>

Upvotes: 0

Views: 1476

Answers (4)

Saqib
Saqib

Reputation: 467

xml

<style name="AppTheme.myNoActionBarTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

Then in manifest.xml

<activity android:name=".NoticeboardActivity" android:theme="@style/AppTheme.myNoActionBarTheme"></activity>

Upvotes: 0

Atiq
Atiq

Reputation: 14835

In my fragments this is how I hide the ActionBar and it works perfectly fine

// MainActivity is the activity which contains fragment
ActionBar actionBar = ((MainActivity) getActivity()).getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }

Upvotes: 1

Dixit Panchal
Dixit Panchal

Reputation: 3436

Try This

actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);

Upvotes: 1

Sathish Kumar J
Sathish Kumar J

Reputation: 4345

Try this @ where you want to hide/show ActionBar,

requestWindowFeature(Window.FEATURE_ACTION_BAR);

// delaying the hiding of the ActionBar
Handler h = new Handler();
h.post(new Runnable() {     
    @Override
    public void run() {
        getActionBar().hide();//OR
        //getActionBar().show();
    }
});

If Activity

getSupportActionBar().hide(); 
or 
getActionBar().hide();

If Fragment

getActivity().getSupportActionBar().hide();
or
getActivity().getActionbar().hide();

Upvotes: 1

Related Questions