IDmikael
IDmikael

Reputation: 477

Transparent status bar with collapsing toolbar in api 19(KitKat)

I'm creating application with collapsing toolbar and transparent status bar. But i've got a problem with api 19 when i set <item name="android:windowTranslucentStatus">true</item> i get this:

I tried to make it by

getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

but the only thing that works is

Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

but after it i receive that app bar is under status bar

enter image description here

my Appbar and Collapsing toolbar layouts have parameter fitsSystemWindows = "true"

in Api 21 and higher all ok.

How can i make transparent status bar with collapsing toolbar layout in api 19? Thanks for any help.

Upvotes: 2

Views: 3395

Answers (2)

IDmikael
IDmikael

Reputation: 477

I solve my issue by this code and it's working perfectly for me:

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        Window w = getWindow(); // in Activity's onCreate() for instance
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) mToolBar.getLayoutParams();
        lp.setMargins(0,24,0,0);
        mToolBar.setLayoutParams(lp);
    }

my mainActivity.xml file is:

        .......blablalba
<android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="210dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginBottom="32dp"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true">

            <ImageView
            android:layout_width="match_parent"
            android:contentDescription="@string/app_name"
            android:id="@+id/ivHeader"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            android:layout_gravity="bottom"
            android:layout_height="235dp" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            app:layout_collapseMode="pin"
            android:layout_gravity="top"
            android:background="@android:color/transparent" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>
.....blalblaba

Upvotes: 2

Jayanth
Jayanth

Reputation: 6297

you have to change fitsSystemWindows = "true" to fitsSystemWindows = "false" for that to work.

and don't write any java code for making full screen, just add below lines inside both styles.xml and v21 styles.xml

<item name="android:windowFullscreen">true</item>

Upvotes: 0

Related Questions