Home Ask Login Register

Developers Planet

Your answer is one click away!

Vasile Doe February 2016

Android custom layout as navigation drawer

I am trying to build a standard simple navigation drawer that have many elements using ArrayAdapter but when click on element I need to load some html into webView inside the drawer, is this possible somehow? expected drawer structure

I was building such a layout for that:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_new_order"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".BaseActivity">

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

        <include layout="@layout/app_bar" />

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

            <include layout="@layout/activity_content_base" />

        </FrameLayout>
    </LinearLayout>

    <!--place for drawer-->
    <FrameLayout
        android:id="@+id/navWeb"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="right|end">

        <include layout="@layout/drawer_test" />

    </FrameLayout>

</android.support.v4.widget.DrawerLayout>

where layout/drawer_test is my cutom layout

Answers


Sabari February 2016

Try this:-

Replace this code(correct place in your code):

<LinearLayout
        android:id="@+id/drawer_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_margin="1dp"
        android:background="@drawable/rounded_corner"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:background="@drawable/rectangle"
            android:orientation="horizontal"
            android:weightSum="100">

            <ListView
                android:id="@+id/drawerList"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="50"
                android:choiceMode="singleChoice"
                android:listSelector="@drawable/list_selector" />

            <WebView
                android:id="@+id/webview"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="50"
                android:background="#888888" />
        </LinearLayout>
    </LinearLayout>

Create 2 drawables, rectangle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#ffffff"/>

    <stroke
        android:width="4dp"
        android:color="@android:color/holo_red_light"/>

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp"/>

</shape>

and rounded_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://s 

Post Status

Asked in February 2016
Viewed 2,328 times
Voted 4
Answered 1 times

Search




Leave an answer


Quote of the day: live life