San Dé
San Dé

Reputation: 43

How to have a text view in my navigation drawer after menu items?


I need to have to have a text view after my menu items, it shouldn't be responsive. I needn't update it programmatically. I'm using a navigation drawer activity. I could create an image out of the text so implementation of image view will help as well. Kind of like this

Upvotes: 2

Views: 5098

Answers (4)

Muhaiminur Rahman
Muhaiminur Rahman

Reputation: 3152

You can try this way.. I am posting details code which might help you

1)This is main class where navigation drawer appears

<?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="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!--<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:background="@color/app_blue"
    app:itemIconTint="@color/app_white"
    app:itemTextColor="@color/app_white">
</android.support.design.widget.NavigationView>-->
<android.support.design.widget.NavigationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer"
    android:background="@color/app_blue"
    app:itemIconTint="@color/app_white"
    app:itemTextColor="@color/app_white">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="match_parent"
        android:scrollbars="vertical">

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

            <android.support.design.widget.NavigationView
                android:id="@+id/nav_view"
                app:elevation="0dp"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"

                app:headerLayout="@layout/nav_header_main"
                app:menu="@menu/activity_main_drawer"
                android:background="@color/app_blue"
                app:itemIconTint="@color/app_white"
                app:itemTextColor="@color/app_white">
                ></android.support.design.widget.NavigationView>

            <LinearLayout
                android:id="@+id/spacer_to_bottom"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="0dp"
                android:layout_weight="1"/>

            <include layout="@layout/nav_footer_main"></include>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

2)this is menu xml class

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_menu_camera"
        android:title="@string/menu_home" />
    <item
        android:id="@+id/nav_reg_log"
        android:icon="@drawable/ic_menu_gallery"
        android:title="@string/menu_reg_log" />
    <item
        android:id="@+id/nav_profile"
        android:icon="@drawable/ic_menu_slideshow"
        android:title="@string/menu_profile" />
    <item
        android:id="@+id/nav_notification"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_notificatio" />
    <item
        android:id="@+id/nav_post_offer"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_post_offer" />
    <item
        android:id="@+id/nav_history"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_history" />
    <item
        android:id="@+id/nav_review"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_review" />
    <item
        android:id="@+id/nav_blog"
        android:icon="@drawable/ic_menu_manage"
        android:title="@string/menu_blog" />
</group>


<!--<item android:title="Communicate">
    <menu>
        <item
            android:id="@+id/nav_share"
            android:icon="@drawable/ic_menu_share"
            android:title="Share" />
        <item
            android:id="@+id/nav_send"
            android:icon="@drawable/ic_menu_send"
            android:title="Send" />
    </menu>
</item>-->
</menu>

3)this is footer xml class

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_blue"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="I am the footer" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="I'm always at the bottom of the sidemenu" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="[email protected]" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Follow Us"
    android:textColor="@color/app_white"
    android:textSize="18sp"
    android:textStyle="bold" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5">
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

Finally you can see this

enter image description here

Upvotes: 0

San D&#233;
San D&#233;

Reputation: 43

I tried using Linear layout,Frame layout,etc. but they didn't have scroll-able behavior. Using group items didn't give the flexibility I wanted for the text view. I got this solution from another answer.

<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"
    app:menu="@menu/activity_nav_drawer__main_drawer">
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_drawer_bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:headerLayout="@layout/nav_footer"/>
</android.support.design.widget.NavigationView>

Aligning another nested navigation view to the bottom and giving it it's own header will have it aligned to the bottom and you can place imageviews or text views in it.

Upvotes: 0

Haniyeh Khaksar
Haniyeh Khaksar

Reputation: 804

I don't know you use which code and version to make navigation menu. but I have 3 suggestions for you. one of them is below code if you use 'android.support.design.widget.NavigationView' :

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:menu="@menu/menu_drawer">

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

    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text="your Sentences" />
</LinearLayout>

another is below code, if you use android.support.v4.widget.DrawerLayout :

    <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" >

<FrameLayout
    android:id="@+id/content_frame"...../>

<RelativeLayout
    android:id="@+id/relative_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start" >

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <TextView
            android:id="@+id/text_view1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Your Sentences" />

    </RelativeLayout>
</RelativeLayout>

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

and last suggestion is that you use different list item in your menu. use getViewTypeCount() and getItemViewType(int position) in your adapter. see this link

Upvotes: 2

Ihor Bykov
Ihor Bykov

Reputation: 1938

<group
    android:id="@+id/first"
    android:checkableBehavior="single">

    <item
        android:id="@+id/item_1"
        android:icon="@drawable/ic_feed_grey_500_24dp"
        android:title="Feed" />
    <item
        android:id="@+id/item_2"
        android:icon="@drawable/ic_explore_grey_500_24dp"
        android:title="Explore" />
    <item
        android:id="@+id/item_4"
        android:icon="@drawable/ic_settings_grey_500_24dp"
        android:title="Settings" />

</group>
<group
    android:id="@+id/second"
    android:checkableBehavior="single">
    <item xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/navi_item_text_layout"
        android:title="Your text layout"
        app:actionLayout="@layout/text_layout"
        app:showAsAction="always" />

</group>

I suppose you already have navigation_view.xml ?

Upvotes: 2

Related Questions