Android 不显示菜单抽屉项
我有用 但在我的手机菜单中没有显示项目 在我的手机中,当我打开菜单时,不显示项目和空白(白色) MainActivty.java中的代码Android 不显示菜单抽屉项,android,android-studio,navigation-drawer,android-menu,Android,Android Studio,Navigation Drawer,Android Menu,我有用 但在我的手机菜单中没有显示项目 在我的手机中,当我打开菜单时,不显示项目和空白(白色) MainActivty.java中的代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findVie
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);
和activity_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>
请使用
navigationListView.addNavigationItem(String title, int imgRes, boolean selected);
要将项目添加到NavigationView,我想您应该将要在导航菜单上显示的每个项目添加到navigationListView
navigationListView.add(new NavigationItem("setting",images[1],true));
我认为这个图书馆不太好,似乎不太受欢迎。尝试使用这个可能会帮助android:textDirection=“rtl”我已经添加了android:textDirection=“rtl”,不要更改!请为此再提出一个问题。。并添加详细信息,如要更改方向的位置