Хорошо, у меня есть эта проблема.Заголовки внутри пунктов меню, которые отображаются в NavigationView, не центрируются вертикально.
В основном я получил DrawerLayout в качестве представления верхнего уровня.NavigationView располагается внутри DrawerLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<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:itemIconPadding="10dp"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
/>
</android.support.v4.widget.DrawerLayout>
Затем у меня есть меню с элементами внутри, разделенными на группы.Например:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/misc">
<item
android:id="@+id/nav_change_account"
android:icon="@drawable/v_change_account"
android:title="Сменить Л/С"
/>
</group>
<group android:id="@+id/menu_main">
<item
android:id="@+id/nav_news"
android:icon="@drawable/ic_library_books_48px_2x"
android:title="НОВОСТИ" />
<item
android:id="@+id/nav_services"
android:icon="@drawable/ic_touch_app_48px2x"
android:title="ЗАЯВКИ" />
<item
android:id="@+id/nav_counter"
android:icon="@drawable/ic_developer_board_48px_2x"
android:title="ВНЕСТИ ПОКАЗАНИЯ СЧЕТЧИКОВ" />
<item
android:id="@+id/nav_my_orders"
android:icon="@drawable/ic_local_activity_48px2x"
android:title="ИСТОРИЯ" />
</group>
</menu>
Я пытался применить тему к NavigationView с различными атрибутами элемента, например:
<style name="NavigationViewPadding">
<item name="android:itemPadding">10dp</item>
<item name="android:listPreferredItemHeight">20dp</item>
<android.support.design.widget.NavigationView
..........
android:theme="@style/NavigationViewPadding"
/>
И это мой код инициализацииinside onCreate ()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View hView = navigationView.getHeaderView(0);
imgProfile = (ImageView) hView.findViewById(R.id.imgProfile2);
txtNameProfile = (TextView) hView.findViewById(R.id.txtNameProfile);
Пытался установить для каждого атрибута элемента значение NavigationView, опробовал буквально все доступные атрибуты для элементов, но ничего не работает.Буду очень признателен за любую помощь.