2016-06-20 17 views
0

Ich möchte eine Kategorie erstellen, um den Namen der Elemente im Menü der Schublade zu trennen. Aber ich habe nur diese in der strings.xml:Wie erstellt man "Kategorie" im Listenelement?

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <string name="app_name">Slider Menu</string> 
    <string name="action_settings">Settings</string> 
    <string name="hello_world">Hello world!</string> 
    <string name="drawer_open">Slider Menu Opened</string> 
    <string name="drawer_close">Slider Menu Closed</string> 

    <!-- Nav Drawer Menu Items --> 
    <string-array name="nav_drawer_items"> 
     <item >Home</item> 
     <item >Connection</item> 
     <item >Register</item> 
     <item >Communities</item> 
     <item >Pages</item> 
     <item >Logout</item> 
    </string-array> 

    <!-- Nav Drawer List Item Icons --> 
    <!-- Keep them in order as the titles are in --> 
    <array name="nav_drawer_icons"> 
     <item>@drawable/ic_home</item> 
     <item>@drawable/ic_people</item> 
     <item>@drawable/ic_photos</item> 
     <item>@drawable/ic_communities</item> 
     <item>@drawable/ic_pages</item> 
     <item>@drawable/ic_whats_hot</item> 
    </array> 

    <!-- Content Description --> 
    <string name="desc_list_item_icon">Item Icon</string> 

</resources> 

Dort ist es mein drawer_list_item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:background="@drawable/list_selector"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="25dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="12dp" 
     android:layout_marginRight="12dp" 
     android:contentDescription="@string/desc_list_item_icon" 
     android:src="@drawable/ic_home" 
     android:layout_centerVertical="true" /> 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@id/icon" 
     android:minHeight="?android:attr/listPreferredItemHeightSmall" 
     android:textAppearance="?android:attr/textAppearanceListItemSmall" 
     android:textColor="@color/list_item_title" 
     android:gravity="center_vertical" 
     android:paddingRight="40dp"/> 

    <TextView android:id="@+id/counter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/counter_bg" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="8dp" 
     android:textColor="@color/counter_text_color"/> 

</RelativeLayout> 

Für exemple Ich mag würde eine Trennung mit einer kleinen Bar machen (oder andere) zwischen "Home" und "Verbindung" ...

Antwort

1

In Ihrer Tätigkeit XML,

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:menu="@menu/activity_main_drawer" /> 

erstellen activity_main_drawer.xml in res> Menü

<group android:checkableBehavior="single"> 
    <item 
     android:id="@+id/nav_gallery" 
     android:icon="@drawable/ic_menu_gallery" 
     android:title="Gallery" /> 
    <item 
     android:id="@+id/nav_slideshow" 
     android:icon="@drawable/ic_menu_slideshow" 
     android:title="Slideshow" /> 
</group> 

<item android:title="Communicate"> 
    <menu> 
     <group android:checkableBehavior="single"> 
      <item 
       android:id="@+id/nav_manage" 
       android:icon="@drawable/ic_menu_manage" 
       android:title="Tools" /> 
     </group> 
    </menu> 
</item> 

Ändern, um die Titel und Symbole auf das, was Sie möchten. Sie können auch app:headerLayout in NavigationView hinzufügen, um eine Kopfzeile über dem Menü zu haben.

+0

Was ist mit der Listdrawer und der Listview in der Zeichenfolge? Ich behalte es auch? – zouarv42

+0

@ zouarv42 'nav_drawer_items' und' nav_drawer_items' werden nicht benötigt. Sie können das Zeichen in 'andorid: icon' beziehen und in' android: title' string. – Joshua

+0

Ich kann die App jetzt nicht öffnen ... http: //www.filedropper.com/thyroid Ich habe eine Navigation und ein Schubladenlayout in der main.xml -> nicht gut? – zouarv42

0

Verwenden Sie eine Menüressource (mit Gruppen) anstelle einer string-array, wie vorgeschlagen here.

+0

Thx für Ihre Antwort, aber sollte ich die Liste behalten? Wie könnte ich tun, weil ich meine Haupt-und nur das Menü ---> activity_main_drawer (neu), das heißt, ich sollte mich entscheiden ... – zouarv42