剂量不显示菜单抽屉项目

时间:2016-12-13 13:00:39

标签: android android-studio navigation-drawer android-menu

我使用https://github.com/lewisjdeane/L-Navigation-Drawer

但在我的手机菜单中没有显示项目 在我的手机中打开菜单时不显示项目和空白(白色)

MainActivty.java中的

代码

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        vorod=(Button) findViewById(R.id.main_vorod);

        NavigationListView navigationListView = (NavigationListView) findViewById(R.id.navigation_list_view);

        int[] images = new int[]{
         R.drawable.setting,
         R.drawable.like
      };


        new NavigationItem("setting",images[1],true);
        new NavigationItem("setting2",images[1],false);
        new NavigationItem("setting3",images[1],false);
        new NavigationItem("setting4",images[1],false);
        navigationListView.setSelectedItem(0);

和actvity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.sayeben.karagah.MainActivity"
    android:background="@mipmap/bg">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    <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">
        <!-- The main content view -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!-- Put your layout design in here -->

        </FrameLayout>
        <!-- The navigation list view -->
        <uk.me.lewisdeane.lnavigationdrawer.NavigationListView
            android:id="@+id/navigation_list_view"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#FFFFFF"/>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

请使用

navigationListView.addNavigationItem(String title, int imgRes, boolean selected); 

将项目添加到NavigationView

答案 1 :(得分:0)

我猜您应该将要在导航菜单上显示的每个项目添加到navigationListView

navigationListView.add(new NavigationItem("setting",images[1],true));