2

I'm trying to make sliding menu full screen but I can't.

If i use android:fitsSystemWindows="false", it's like the first picture in the photo.

If i use android:fitsSystemWindows="true", it's like the second picture in the photo. Sliding menu is staying under the ActionBar.

But I want to show the menu like third picture in the photo. How can I do it? What should I change?

nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/view_container"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:gravity="bottom"
    android:orientation="vertical"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:orientation="vertical"
        android:padding="@dimen/padding_nav_activity_horizontal">

        <ImageView
            android:layout_width="75dp"
            android:layout_height="75dp"
            android:paddingTop="@dimen/padding_nav_activity_vertical"
            android:contentDescription="@null"
            app:srcCompat="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/nav_header_main_app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/padding_nav_header_vertical_spacing"
            android:text="@string/app_name"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/app_version" />
    </LinearLayout>
</RelativeLayout>

activity_main.xml

<?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="false"
    tools:context=".MainActivity"
    tools:openDrawer="start">

    <RelativeLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabMode="scrollable"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/tab_layout"/>
    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        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>

MainActivity.java

    private ActionBarDrawerToggle toggle;
    private DrawerLayout drawer;
    private NavigationView navigationView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        toggle = new ActionBarDrawerToggle(
                this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        toggle.syncState();

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    public boolean onOptionsItemSelected(final MenuItem item) {

        if (toggle.onOptionsItemSelected(item)){
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public boolean onNavigationItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId()) {
            case R.id.nav_item_1:
                return true;
        }
        return true;
    }

    public void onBackPressed() {
        assert drawer != null;
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }
}
Ali
  • 3,346
  • 4
  • 21
  • 56
TheAnswer042
  • 61
  • 1
  • 6
  • The answer on the linked duplicate now at the top of your question has an example. They're using a `` for the drawer, but it's exactly the same for a ``. – Mike M. Nov 28 '18 at 09:16
  • I tried the answer on the other page. The same as the second picture in the photo. Not like I want. @Mike M. – TheAnswer042 Nov 28 '18 at 09:49
  • It doesn't look as though you did. Where's the `` in your layout? – Mike M. Nov 28 '18 at 09:51
  • It's OK when I added Toolbar instead of ActionBar. Can't I do this with ActionBar? @Mike M. – TheAnswer042 Nov 28 '18 at 10:15
  • Possibly. It would take some fiddling with the `View` hierarchy at runtime, though. I showed how to get the drawer to open over the decor `ActionBar` on [this post](https://stackoverflow.com/q/35150125), but I don't recall if we ever got it to go under the status bar. I might do a quick test, later, when I get some time. – Mike M. Nov 28 '18 at 10:23
  • 1
    Thank you very much for all answers. – TheAnswer042 Nov 28 '18 at 10:36
  • In case you're still interested in whether we can do this with the decor-provided `ActionBar`, I just ran a quick test, and yes, it is possible, with a very slight modification to my code in the example I linked above. However, I wouldn't really recommmend doing that. If you really want to, let me know, and I'll tell you what to change. – Mike M. Nov 28 '18 at 19:19

0 Answers0