0

i try to set transparant status bar android, but fit system windows not work on ViewPager. Its Still not full windows like this... enter image description here and this my xml.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true" />

        <LinearLayout ../>

        <View ../>

        <Button../>

        <Button../>

    </RelativeLayout>

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

Can you help me, how to fix it ? thanks

Amay Diam
  • 2,561
  • 7
  • 33
  • 57
  • `android:fitsSystemWindows="true"` *by default* means 1. take the window insets, 2. apply them as my padding, 3. do not propagate the insets any further. That's the default behavior. `CoordinatorLayout` is special, it allows its children to react based on `Behavior`. But that's needlessly complicated for you now. Read this: https://medium.com/androiddevelopers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec I'll mark this as duplicate because another question already has a very nice answer which will help you. – Eugen Pechanec Feb 05 '19 at 20:47
  • You'll need to propagate the `WindowInsets` to children of the `ViewPager`. – Eugen Pechanec Feb 05 '19 at 20:50

1 Answers1

0

Try to add this to your theme in styles.xml

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

another way is

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                      WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

The following code shows how to hide and show the status and navigation bars in your activity, without resizing your layout in response to the changing screen space:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void hideSystemUI() {
    // Enables regular immersive mode.
    // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
    // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN);
}

// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Khaled Qasem
  • 879
  • 7
  • 20