导航抽屉组标题 - 如何设置?

时间:2015-07-28 13:51:25

标签: android navigation-drawer

我有一个包含如下组的菜单。是否可以为每个组设置标题?我知道子菜单是可能的,但是对于第一级别组呢?

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single" android:id="@+id/main_group">
        <item
            android:id="@+id/leagues_in_progress_item"
            android:icon="@drawable/ic_format_line_spacing_black_48dp"
            android:title="@string/title_activity_leagues_in_progress" />
        <item
            android:id="@+id/last_matches_item"
            android:icon="@drawable/ic_access_alarm_black_48dp"
            android:title="@string/title_activity_last_matches" />
    </group>
    <group android:checkableBehavior="single" android:id="@+id/another_group">

        <item
            android:id="@+id/archive_item1"
            android:icon="@drawable/ic_folder_open_black_48dp"
            android:title="@string/title_activity_archive" />
        <item
            android:id="@+id/put_score_item3"
            android:icon="@drawable/ic_add_circle_outline_black_48dp"
            android:title="@string/title_activity_put_score" />
    </group>
</menu>

1 个答案:

答案 0 :(得分:0)

是的,每个组在您的顶级树中都是item。然后只需为每个属性设置title属性。使用你的代码就像这样:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:title="First group"
        android:id="@+id/first_group">
        <menu android:checkableBehavior="single" android:id="@+id/main_group">
            <item
                android:id="@+id/leagues_in_progress_item"
                android:icon="@drawable/ic_format_line_spacing_black_48dp"
                android:title="@string/title_activity_leagues_in_progress" />
            <item
                android:id="@+id/last_matches_item"
                android:icon="@drawable/ic_access_alarm_black_48dp"
                android:title="@string/title_activity_last_matches" />
        </menu>
    </item>

    <item
        android:title="Second group"
        android:id="@+id/second_group">
        <menu android:checkableBehavior="single" android:id="@+id/another_group">

            <item
                android:id="@+id/archive_item1"
                android:icon="@drawable/ic_folder_open_black_48dp"
                android:title="@string/title_activity_archive" />
            <item
                android:id="@+id/put_score_item3"
                android:icon="@drawable/ic_add_circle_outline_black_48dp"
                android:title="@string/title_activity_put_score" />
        </menu>
    </item>
</menu>