Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Navigation Drawer vertical border

I want to make my NavigationDrawer just like in this app

enter image description here

and more specifically, I want to add that little 1 pixel border on the right side

enter image description here

but here is what I am getting with my drawer enter image description here

and this is the xml of the drawer fragment

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E7E7E7"
android:choiceMode="singleChoice"
android:dividerHeight="0.5dp" />

What do I have to do?

like image 988
Sartheris Stormhammer Avatar asked Mar 04 '15 21:03

Sartheris Stormhammer


People also ask

How to create a custom navigation drawer in Android</strong>?

How to create a custom navigation drawer in Android? This example demonstrate about How to resize Image in Android App. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

How do I navigate the navigation drawer?

With the navigation drawer one can navigate to many screens or functionalities of the app by clicking on the ‘hamburger’ icon. Swiping from the left is also a way to bring the drawer into view, a screen then slides in, showing many items.

What is a modal navigation drawer?

They are elevated above most of the app’s UI and don’t affect the screen’s layout grid. They are primarily for use on mobile where screen space is limited, and can be replaced by standard drawers on tablet and desktop. The following example shows a modal navigation drawer with a top app bar.

How to add navigation header in Android Studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to res/layout/nav_header_main.xml.


1 Answers

Try this,

DrawerLayout mDrawerLayout;

onCreate(Bundle ...){
    //...
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
                    GravityCompat.START);
    //...
}

EDIT

You need to add one View along with ListView and wrap both with one LinearLayout horizontally and give both some weight. Here I have given 0.99 weight to listView and 0.01 weight to view, you can change it as per your requirement.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

        <ListView android:id="@+id/drawer_list"
            android:layout_weight="0.99"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#E7E7E7"
            android:choiceMode="singleChoice"
            android:dividerHeight="0.5dp" />

        <View
            android:layout_weight="0.01"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#eeccbb"/>
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>
like image 154
Apurva Avatar answered Oct 20 '22 07:10

Apurva