1. group 하나로 묶었을 경우
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group
android:id="@+id/menu_top"
android:checkableBehavior="single">
<item
android:id="@+id/nav_movielist"
android:icon="@drawable/ic_list"
android:title="@string/menu_movielist" />
<item
android:id="@+id/nav_movieapi"
android:icon="@drawable/ic_review"
android:title="@string/menu_movieapi" />
<item
android:id="@+id/nav_reservation"
android:icon="@drawable/ic_book"
android:title="@string/menu_reservation" />
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="@string/menu_settings" />
</group>
</menu>
구분선 없이 모두 모여 나타남.
2. group만 나눈 경우
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_movielist"
android:icon="@drawable/ic_list"
android:title="@string/menu_movielist" />
<item
android:id="@+id/nav_movieapi"
android:icon="@drawable/ic_review"
android:title="@string/menu_movieapi" />
<item
android:id="@+id/nav_reservation"
android:icon="@drawable/ic_book"
android:title="@string/menu_reservation" />
</group>
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="@string/menu_settings" />
</group>
</menu>
똑같이 구분선 없이 하나의 그룹처럼 보임.
3. group을 나눈 뒤 각자 다른 id 부여
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group
android:id="@+id/menu_movie"
android:checkableBehavior="single">
<item
android:id="@+id/nav_movielist"
android:icon="@drawable/ic_list"
android:title="@string/menu_movielist" />
<item
android:id="@+id/nav_movieapi"
android:icon="@drawable/ic_review"
android:title="@string/menu_movieapi" />
<item
android:id="@+id/nav_reservation"
android:icon="@drawable/ic_book"
android:title="@string/menu_reservation" />
</group>
<group
android:id="@+id/menu_setting"
android:checkableBehavior="single">
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="@string/menu_settings" />
</group>
</menu>
구분선이 생겨 그룹이 나뉘어진 걸 식별할 수 있음.
1. group을 나눈 뒤 menu와 item 태그로 한번 더 감쌈.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group
android:id="@+id/menu_movie"
android:checkableBehavior="single">
<item
android:id="@+id/nav_movielist"
android:icon="@drawable/ic_list"
android:title="@string/menu_movielist" />
<item
android:id="@+id/nav_movieapi"
android:icon="@drawable/ic_review"
android:title="@string/menu_movieapi" />
<item
android:id="@+id/nav_reservation"
android:icon="@drawable/ic_book"
android:title="@string/menu_reservation" />
</group>
<item android:title="설정">
<menu>
<group
android:id="@+id/menu_settings"
android:checkableBehavior="single">
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="@string/menu_settings" />
</group>
</menu>
</item>
</menu>
item에 title을 설정한 뒤 감싸주었더니 구분선과 함께 label이 나타난 것을 확인.
'Android > Errors' 카테고리의 다른 글
OptionMenu의 item에 actionLayout 지정 시 onOptionsItemSelected() 미작동 (0) | 2020.05.08 |
---|---|
No Network Security Config specified, using platform default (1) | 2020.05.03 |
Fragment에서 ViewPager 사용 시 문제점 (0) | 2020.04.20 |
Navigation Drawer Activity에서 Fragment 전환 (0) | 2020.04.20 |
Fragment에서 startActivityForResult 사용 시 문제점 (0) | 2020.04.20 |