Java 更改NavigationView中项目的样式
我有一个抽屉布局,里面有NavigationView(支持设计库)。我已经能够设置标题和添加项目的看法,但我想有一些项目有较小的文字,没有图标,等等。。。我不知道在哪里指定新属性。在我的drawer.xml中,其他项目都在那里,我不知道哪些属性可以更改它 任何建议都将不胜感激 我有两个项目与预期的外观和最后一个项目,注销,我想使更小,并有一个分隔器的开销 layout/activity\u main.xmlJava 更改NavigationView中项目的样式,java,android,xml,androiddesignsupport,navigationview,Java,Android,Xml,Androiddesignsupport,Navigationview,我有一个抽屉布局,里面有NavigationView(支持设计库)。我已经能够设置标题和添加项目的看法,但我想有一些项目有较小的文字,没有图标,等等。。。我不知道在哪里指定新属性。在我的drawer.xml中,其他项目都在那里,我不知道哪些属性可以更改它 任何建议都将不胜感激 我有两个项目与预期的外观和最后一个项目,注销,我想使更小,并有一个分隔器的开销 layout/activity\u main.xml <!-- A DrawerLayout is intended to be u
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<LinearLayout
android:orientation="vertical"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/fragment_navdrawer_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
<?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/navigation_item_1"
android:icon="@drawable/ic_action_social_school"
android:title="Courses"/>
<item
android:id="@+id/navigation_item_2"
android:icon="@drawable/ic_action_action_grade"
android:title="Grades"/>
<item
android:id="@+id/navigation_logout"
android:title="Logout"
/>
</group>
</menu>
菜单/drawer.xml
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<LinearLayout
android:orientation="vertical"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/fragment_navdrawer_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
<?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/navigation_item_1"
android:icon="@drawable/ic_action_social_school"
android:title="Courses"/>
<item
android:id="@+id/navigation_item_2"
android:icon="@drawable/ic_action_action_grade"
android:title="Grades"/>
<item
android:id="@+id/navigation_logout"
android:title="Logout"
/>
</group>
</menu>
以下是您的
活动\u main.xml
应该是怎样的。工具栏已注释掉,但如果需要,请取消注释并添加工具栏布局。在页面底部添加注销按钮和分隔符视图,并按照列表视图中项目的外观设置它们的样式
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
/* <include
android:id="@+id/tool_bar"
layout="@layout/tool_bar">
</include> */
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
//devider
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:alpha="0.2"
android:background="@android:color/white" />
//logout button
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingTop="4dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txtLogout" />
</android.support.v4.widget.DrawerLayout>
这只是你的抽屉应该是什么样子的一个草图,但是你可以重新设计你的标题来显示图像和所有东西。下面是两个很好的链接,详细解释了这一点
希望这有帮助您的答案无效@Evan Ogra使用的是
NavigationView
,但是,您的答案是基于NavigationDrawer
找到解决方案了吗?我也面临着这个问题,尽管我正在考虑将navigationview和其他视图放在一个视图组中。我不知道这样行不行?