简体   繁体   中英

menu layout for the navigation menu is not showing up in the navigation drawer

It's hard to figure out what the problem is because there are no syntax errors. Basically I'm able to slide the navigation menu, but the menu layout is not working.

Here's my code.

activity_main.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.isaacdixon.pro3.MainActivity">


    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        >
        <include
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            layout="@layout/toolbar_layout"
                />
    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/navigation_view"
        android:layout_gravity="start"
        app:menu="@menu/drawer_menu"
        />

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

MainActivity.java

package com.example.isaacdixon.pro3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
}

drawer_menu.xml

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

    <group android:checkableBehavior="single">

        <items
            android:id="@+id/home_id"
            android:title="Home"
            android:icon="@drawable/glass"
                ></items>
        <items
            android:id="@+id/messege_id"
            android:title="Messege"
            android:icon="@drawable/draw"
            ></items>
        <items
            android:id="@+id/setting_id"
            android:title="Setting"
            android:icon="@drawable/settings"
            ></items>
    </group>
        <item android:title="Social">
            <menu>
                <items
                    android:id="@+id/facebook_id"
                    android:title="FaceBook"
                    android:icon="@drawable/facebook"
                    >
                </items>
                <items
                    android:id="@+id/twiter_id"
                    android:title="Twiter"
                    android:icon="@drawable/twitter"
                    >
                </items>
            </menu>
        </item>
</menu>

Problem with your items .

Just edit your menu like below.

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

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/..."
            android:icon="@android:drawable/..."
            android:title=.../>
        <item
            android:id="@+id/...
            android:icon="@android:drawable/..."
            android:title="..."/>
        <item
            android:id="@+id/..."
            android:icon="@android:drawable/..."
            android:title="..."/>
        <item
            android:id="@+id/..."
            android:icon="@android:drawable/..."
            android:title="..."/>
    </group>

    <item android:title="Social">
        <menu>
            <item
                android:id="@+id/..."
                android:icon="@android:drawable/..."
                android:title="..."/>
            <item
                android:id="@+id/..."
                android:icon="@android:drawable/..."
                android:title="..."/>
        </menu>
    </item>

</menu>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM