1

I recently opened a project in Android Studio and selected a Navigation Drawer Activity. It created the navigation drawer, except that it's being displayed in a way that I don't like - the navigation drawer is displayed on top of the title bar, for example:

Instead, I'd like it to be like:

In this "correct" example, the title bar - "Home" is being displayed, alongside a closing arrow, while the navigation drawer opens.

File sources:

app_bar_main.xml

<?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"
    tools:context="com.avi12.soundcloudinstantdownloader.MainActivity"
    android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

<RelativeLayout
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.avi12.soundcloudinstantdownloader.MainActivity"
    tools:showIn="@layout/app_bar_main">


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_margin="5dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:text="What this app can download:"/>

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView"
        android:layout_alignStart="@+id/textView"
        android:layout_below="@+id/textView"
        android:layout_marginLeft="17dp"
        android:layout_marginStart="17dp"
        android:text="Single tracks"/>

    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView8"
        android:layout_alignStart="@+id/textView8"
        android:layout_below="@+id/textView8"
        android:text="Playlists, a.k.a albums"/>

    <TextView
        android:id="@+id/textView10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView9"
        android:layout_alignStart="@+id/textView9"
        android:layout_below="@+id/textView9"
        android:text="User likes (though only some, due to SoundCloud limiting their API)"/>

    <TextView
        android:id="@+id/textView11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView"
        android:layout_alignStart="@+id/textView"
        android:layout_below="@+id/textView10"
        android:layout_marginTop="12dp"
        android:text="Instantly download songs by sharing it from SoundCloud with this app!"/>

    <TextView
        android:id="@+id/textView12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView11"
        android:layout_alignStart="@+id/textView11"
        android:layout_below="@+id/textView11"
        android:layout_marginTop="18dp"
        android:text="Alternatively, you can search the song, and even paste its URL:"/>

    <EditText
        android:id="@+id/inputDownload"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView12"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignStart="@+id/textView12"
        android:layout_below="@+id/textView12"
        android:ems="10"
        android:hint="Search query or URL"
        android:inputType="textUri"
        android:singleLine="true"/>

    <TextView
        android:id="@+id/error"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        />
</RelativeLayout>

EDIT

After Tomer Shemesh's suggestion, the <android.support.v7.widget.Toolbar was changed to:

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        android:layout_marginTop="?attr/actionBarSize"/>

And then, the result is:

So there is no solution just yet.

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
avi12
  • 2,000
  • 5
  • 24
  • 41

1 Answers1

5

Adding to Tomer suggestion, android:layout_marginTop="?attr/actionBarSize" should be applied to android.support.design.widget.NavigationView. I dont see Navigation View in app_bar_main.xml.

Adding this will give you action bar with a opaque overlay. It will look like this Image with opaque overlay

You can remove opaque overlay by setting scrimColor to transparent of DrawerLayout in your Navigation Drawer Activity.

mDrawerLayout = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_refonte_base, null); mDrawerLayout.setScrimColor(ContextCompat.getColor(this,android.R.color.transparent));

Now it will look like this. Image with scrim color as transparent

Vishu
  • 326
  • 2
  • 11
  • There is no `android.support.design.widget.NavigationView` because Android Studio didn't generate it for some reason. The `` but I prefer to have all the code in the same place, so I just put the referenced code in the same XML file. – avi12 Feb 20 '18 at 16:15
  • Oh wait. Just found the ` – avi12 Feb 20 '18 at 16:17
  • Tested. It [ALMOST](https://i.imgur.com/ibp8Ykh.png) worked (didn't apply the transparency yet). – avi12 Feb 20 '18 at 16:29
  • avi - did this work? can you please accept this solution? – Vishu Feb 22 '18 at 08:59
  • I sadly ended giving up on a navigation drawer, and instead using bottom tabs and as of now I'm working on the code and not on the UI – avi12 Feb 25 '18 at 16:38