adam0404 February 2016

Adding a fragment with custom view to sliding navigation

I want to have a navigation drawer but with arbitrary views inside of it. Not only list items. Is it possible? What library should I use to implement this?

Answers


Gem February 2016

"Is it possible?"
Ans: YES

"What library should I use to implement this?"

Ans: Navigation Drawer in android sdk will work perfectly.

Official Doc: http://developer.android.com/training/implementing-navigation/nav-drawer.html

DrawerLayoutclass is a child class of ViewGroup, this means it has all the features of a view group. We are not restricted to only Listview but we can add any type of view inside DrawerLayout.

Example:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_dark">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Content of drawer"
        android:textColor="@android:color/holo_red_dark"
        android:textSize="24sp"
        />

</FrameLayout>
<!-- The navigation drawer -->
<RelativeLayout
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#12D"
    >

    <TextView
        android:id="@+id/drawer_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Custom view"
        android:textColor="@android:color/secondar 


androidnoobdev February 2016

Check this hope it will help you in understanding navigation view.

https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer

Post Status

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

Search




Leave an answer