Remove gap from navigation drawer layout
Asked Answered
D

2

6

I have created an application that has a navigation view.

when the application in fullscreen then I open that navigation-view that shows me the black overlay on top of navigation-view and also shows me the gap between the bottom of the screen and the bottom of navigation-view. For that.

  • xml code
<?xml version="1.0" encoding="utf-8"?>

<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start">

    ...

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        tools:ignore="RtlSymmetry">

        <!--PlayList Layout-->
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rcvVideoPlaylist"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            android:fitsSystemWindows="false"
            tools:listitem="@layout/item_video_playlist" />

    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>
  • for fullscreen code
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

anyone give me the solution to remove that overlay from navigation-view and gap in that navigation-view

Dictation answered 6/1, 2020 at 12:51 Comment(11)
your target is to make transparent?Osmo
No, just remove that overlay from navigation-view.Dictation
What do you mean by saying overlay? What part you want to get rid of?Urology
sorry for question header, i want to remove that gap from navigation-view that show in second imageDictation
please bring clarity in the question and specify what exactly you want. You can even point it out in the image by circling the specified partLananna
sorry for that, I will update that description.Dictation
I need a solution for both problems (Overlay and gap).Dictation
you question is not clear at all, please update question details and Images with marking of what you want and what you don't want. Also why is there white space in right of Black, is it intended?Kr
I have updated the question and the description. so, now it understandable for you guysDictation
Maybe this is an issue with your Android Emulator. You can check this on your Physical DevicePrefer
oh, is it Bcz I try in Boundary device and that shows the same behavior.Dictation
D
0

you can use this code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <include
                layout="@layout/app_bar_main"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <android.support.v7.widget.RecyclerView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:id="@+id/rv">
            </android.support.v7.widget.RecyclerView>

        </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
Divulsion answered 15/1, 2020 at 10:42 Comment(0)
K
0

You can use this class for fullscreen Activity where status and navigation view does not bleed into NavigationView.

I had the same problem and tried the combination of system flags and found the right combination.

// Removes bleeding transparency onto navigation-view

getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Here is my fullscreen Activity.

public class FullScreenAppCompatActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT < 14) {
            getWindow().requestFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            hideSystemUI();
        }
    }

    /*
     * ************ SETTING FULLSCREEN TRANSITIONS ************
     */

    /**
     * Hide Status and Navigation bars
     */
    @SuppressLint("InlinedApi")
    public void hideSystemUI() {

        View decorView = getWindow().getDecorView();

        // Hide both the navigation bar and the status bar.
        // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and
        // higher, but as
        // a general rule, you should design your app to hide the status bar
        // whenever you
        // hide the navigation bar.
        // Navigation bar hiding: Backwards compatible to ICS.

        // SELECTIVE FLAGS final code: 5890
        // setSelectedFlags(decorView);

        // NO SELECTION OF SDK_INT flag final cod: 5894
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                // Views can use nav bar space if set
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                // Navigation bar hiding: Backwards compatible to ICS.
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                // Status bar hiding: Backwards compatible to Jellybean
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                // Immersive mode: Backward compatible to KitKat.
                // Note that this flag doesn't do anything by itself, it only
                // augments the behavior
                // of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of
                // this sample
                // all three flags are being toggled together.
                // Note that there are two immersive mode UI flags, one of which
                // is referred to as "sticky".
                // Sticky immersive mode differs in that it makes the navigation
                // and status bars
                // semi-transparent, and the UI flag does not get cleared when
                // the user interacts with
                // the screen.
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        // Removes bleeding transparency onto navigation-view
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

    private void setSelectedFlags(View decorView) {
        int selectedFlags = 0;
        if (Build.VERSION.SDK_INT >= 14) {
            selectedFlags ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            Toast.makeText(getApplicationContext(), "View.SYSTEM_UI_FLAG_HIDE_NAVIGATION flag " + selectedFlags,
                    Toast.LENGTH_SHORT).show();
        }

        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16) {
            selectedFlags ^= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    // Views can use nav bar space if set
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

            Toast.makeText(getApplicationContext(), "View.SYSTEM_UI_FLAG_FULLSCREEN flag " + selectedFlags,
                    Toast.LENGTH_SHORT).show();
        }

        if (Build.VERSION.SDK_INT >= 19) {
            selectedFlags ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }
        Toast.makeText(getApplicationContext(), "Final SELECTED flag " + selectedFlags, Toast.LENGTH_SHORT).show();
        decorView.setSystemUiVisibility(selectedFlags);

        int currentVisibility = getWindow().getDecorView().getSystemUiVisibility();
        Toast.makeText(getApplicationContext(), "Initial visibility flag " + currentVisibility, Toast.LENGTH_SHORT)
                .show();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            hideSystemUI();
        }
    }
}
Kimmie answered 16/1, 2020 at 3:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.