Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationView is not visible but item click is working

I want to setup navigation drawer using NavigationView. Items are not visible but when we click on the empty area, particular item click code is getting executed. It looks items are invisible but clickable.

I've tried to play with background colour but it doesn't seems to work.

Any help would be appreciated.

home.xml

<?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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:fitsSystemWindows="true"
tools:context=".Home.HomeActivity">

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

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar" />

    <!-- Main Content -->

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</LinearLayout>


<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/White">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/White"
        android:orientation="vertical"
        android:weightSum="1">

        <android.support.design.widget.NavigationView
            android:id="@+id/NavigationView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="start"
            android:layout_weight="1"
            android:background="@color/White"
            android:fitsSystemWindows="true"
            android:scrollbars="none"
            app:elevation="0dp"
            app:headerLayout="@layout/navigation_header"
            app:itemIconTint="@color/YellowOrange"
            app:itemTextColor="@color/Black"
            app:menu="@menu/nav_menu" />

        <com.squawkinit.orionfreightelite.customview.CustomTextView
            android:id="@+id/tvAppVersion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:padding="10dp"
            android:textColor="@color/Black"
            android:textSize="14sp" />

    </LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

nav_menu.xml(Menu)

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

<group android:checkableBehavior="single">

    <item
        android:id="@+id/dashboardMenu"
        android:title="@string/dashboard_menu" />

    <item
        android:id="@+id/eLogMenu"
        android:title="@string/eLog_menu" />

    <item
        android:id="@+id/emergencyMenu"
        android:title="@string/emergency_menu" />


    <item
        android:id="@+id/syncMenu"
        android:actionLayout="@layout/sync_status"
        android:title="@string/sync_menu" />

    <item
        android:id="@+id/manifestMenu"
        android:title="@string/manifest_menu" />

    <item
        android:id="@+id/groupMessagingMenu"
        android:title="@string/group_messaging_menu" />


    <item
        android:id="@+id/helpMenu"
        android:title="@string/help_menu" />

    <item
        android:id="@+id/logoutMenu"
        android:title="@string/logout_menu" />
</group>

navigation_header.xml

 <?xml version="1.0" encoding="utf-8"?> 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@color/White">

<LinearLayout
    android:id="@+id/navigationHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/accent_material_dark"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/ivDrawerIcon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="20dp"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/orion_elite_logo" />

    <com.squawkinit.orionfreightelite.customview.CustomTextView
        android:id="@+id/tvDrawerName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/White"
        android:textSize="16sp" />

    <com.squawkinit.orionfreightelite.customview.CustomTextView
        android:id="@+id/tvDrawerMobile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="5dp"
        android:textColor="@color/LightWhite"
        android:textSize="14sp" />
</LinearLayout>

CustomTextView

public class CustomTextView extends TextView {

public CustomTextView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub

    if (!isInEditMode())
        setCustomFont(context);
}

public CustomTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub

    if (!isInEditMode())
        setCustomFont(context);
}

public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub

    if (!isInEditMode())
        setCustomFont(context);
}

public void setCustomFont(Context ctx) {

    Typeface tf = Typeface.createFromAsset(ctx.getAssets(),
            "fonts/DroidSerif_Regular.ttf");

    setTypeface(tf);

  }
 }

Theme

 <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">@color/Black</item>
    <item name="android:textColorPrimary">@color/Black</item>
    <item name="android:textColorSecondary">@color/Black</item>
    <item name="colorAccent">@color/Orange</item>
    <item name="textColor">@color/Black</item>
</style>

Navigation Drawer

like image 564
moDev Avatar asked Nov 06 '16 08:11

moDev


People also ask

How to use navigation drawer in android app?

The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar. The drawer icon is displayed on all top-level destinations that use a DrawerLayout.

How do I add a navigation drawer in Mainactivity?

To add a navigation drawer, first declare a DrawerLayout as the root view. Inside the DrawerLayout , add a layout for the main UI content and another view that contains the contents of the navigation drawer.


1 Answers

Finally!! I made it working.

In navigation_header root layout height should be wrap_content instead of match_parent

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" // This should be wrap_content
android:background="@color/White">

<LinearLayout
android:id="@+id/navigationHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/accent_material_dark"
android:orientation="vertical">

<ImageView
    android:id="@+id/ivDrawerIcon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginTop="20dp"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/orion_elite_logo" />

<com.squawkinit.orionfreightelite.customview.CustomTextView
    android:id="@+id/tvDrawerName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:textColor="@color/White"
    android:textSize="16sp" />

<com.squawkinit.orionfreightelite.customview.CustomTextView
    android:id="@+id/tvDrawerMobile"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="5dp"
    android:textColor="@color/LightWhite"
    android:textSize="14sp" />

like image 139
moDev Avatar answered Oct 24 '22 11:10

moDev