Изменить стиль элемента в NavigationView

У меня есть DrawerLayout с NavigationView (библиотекой поддержки дизайна) внутри. Мне удалось установить заголовок и добавить элементы в представление, но я хотел бы, чтобы некоторые элементы имели меньший текст, без значков и т. д. Я не могу понять, где я могу указать новые атрибуты. В моем drawer.xml, где находятся другие элементы, я не знаю, какие атрибуты могут его изменить.

Любой совет приветствуется!

Текущий вид (изображение)

У меня есть два элемента с предполагаемым внешним видом, и последний элемент, выход из системы, я хочу сделать меньше и иметь над ним разделитель.

Желаемый вид (изображение)

макет/activity_main.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>

меню/drawer.xml

<?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>

person Evan Ogra    schedule 28.06.2015    source источник
comment
Вы нашли решение для этого? Я также сталкиваюсь с этой проблемой, хотя я думаю о том, чтобы поместить навигационное представление и другое представление в одну группу просмотра. Интересно, сработает ли это?   -  person John Ernest Guadalupe    schedule 09.11.2015


Ответы (1)


Вот каким должен быть ваш activity_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>

Вместо drawer.xml добавьте новый макет item_row. Это для каждой строки в recyclerView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:orientation="horizontal">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rowIcon"
        android:paddingLeft="16dp"
        android:src="@drawable/ic_launcher"/>

    <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/rowText" />

</LinearLayout>

Это всего лишь набросок того, как должны выглядеть ваши ящики, но вы можете изменить дизайн своего заголовка, чтобы показать изображения и все остальное. Ниже приведены несколько отличных ссылок, которые подробно объясняют это.

Как сделать навигационный ящик в стиле Material Design с заголовком Просмотр

Начало работы с Material Design для Android

Надеюсь это поможет

person Rasika Sugathadasa    schedule 28.06.2015
comment
Ваш ответ недействителен. @Evan Ogra использует NavigationView, однако ваш ответ основан на NavigationDrawer - person ; 17.09.2015