Я пытаюсь установить пользовательский элемент фона на отмеченный элемент фона.и я применил некоторые решения, включая настройку app:itemBackground
для NavigationView, но он не работает аналогично, я попытался activatedBackgroundIndicator
внутри темы, но у меня это тоже не сработало.Есть ли какое-либо возможное решение для этого без использования представления переработчика внутри NavigationView.![Navigation item checked image](https://i.stack.imgur.com/bBYqp.png)
с использованием itemBackground:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:itemBackground="@drawable/navigation_item_selector"
>
</android.support.design.widget.NavigationView>
Использование темы:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:theme="@style/ThemeOverlay.AppCompat.navTheme"
/>
Тема:
<style name="ThemeOverlay.AppCompat.navTheme">
<!-- Color of text and icon when SELECTED -->
<item name="colorPrimary">@color/white</item>
<item name="android:activatedBackgroundIndicator">@drawable/navigation_item_selector</item>
</style>
селектор:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_checked="true">
<shape android:shape="rectangle" >
<corners
android:topLeftRadius="@dimen/radius_round_btn"
android:topRightRadius="@dimen/radius_round_btn"
/>
<solid android:color="@color/colorAccent"/>
</shape>
</item>
</selector>