почему не сделать так?

1. разметка активити с NavigationView внутри CardView
Кликните здесь для просмотра всего текста
XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fefefe"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:title="@string/app_name"
app:titleTextColor="#fff" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<android.support.design.widget.NavigationView
android:id="@+id/navView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/popup_menu1" />
</android.support.v7.widget.CardView>
</LinearLayout> |
|
2. просто любое меню с иконками
Кликните здесь для просмотра всего текста
XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:id="@+id/group1">
<item
android:title="Title"
app:showAsAction="always" />
</group>
<item
android:icon="@drawable/ic_tab_books"
android:title="Item 1"
app:showAsAction="always" />
<item
android:icon="@drawable/ic_tab_movies"
android:title="Item 2"
app:showAsAction="always" />
<item
android:icon="@drawable/bookmarks"
android:title="Item 3"
app:showAsAction="always" />
<item
android:icon="@drawable/ic_folder"
android:title="Item 4"
app:showAsAction="always" />
<item
android:icon="@drawable/ic_hamburger"
android:title="Item 5"
app:showAsAction="always" />
</menu> |
|
3. PROFIT
Title задается как group в меню
плюсы - не нужно вообще ничего писать, кроме одной строчки - все идет из коробки - стили, отступы, цвета, слушатель тот же что и на менюшке
если надо что-то не стандартное то делается свое View и назначается в xml разметке ресурса меню как actionView