2015-06-28 5 views
0

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

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

Current Look (Image)

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

Desired Look (Image)

макет/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> 
+0

Вы нашли решение для этого? Я столкнулся с этой проблемой, хотя я думаю о том, чтобы включить навигацию и другую точку зрения в одну группу просмотра. Интересно, будет ли это работать? –

ответ

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> 

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

How To Make Material Design Navigation Drawer With Header View

Android Getting Started with Material Design

Надеется, что это помогает

+0

Ваш ответ недействителен. @Evan Ogra использует 'NavigationView', однако ваш ответ основан на' NavigationDrawer' – plopd

Смежные вопросы