我试图找到一种方法,在我的NavigationView中的所选项目上有一条垂直线。我试图通过xml设置将其设置为:
app:itemBackground="@drawable/nav_selected_item"
但这只是将drawable应用于整个菜单项列表。
这是我的抽屉:
<android.support.design.widget.NavigationView
android:id="@+id/nav_drawer"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/primary_blue"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_drawer_header"
app:itemBackground="@drawable/nav_drawer_selected"
app:menu="@menu/nav_drawer_view" />
默认行为(当itemBackground attr未设置为nav_drawer_selected时)当前在仅选定的项目上设置透明的浅色调。当我设置它时,它不再具有该行为。是使用选择器的默认itemBackground吗?我将如何有效地解决这个问题?我只想让一个项目使用我的drawable,如果它被选中/当前在视图中,则不将整个样式应用于整个列表。
谢谢!
编辑:显然,这已被其他用户确认为缺陷。 https://code.google.com/p/android/issues/detail?id=176570
他们说这是为了#34; FutureRelease&#34; ...是否有当前的解决方法?或者我是不是试图以编程方式处理这个问题?
答案 0 :(得分:0)
作为一种解决方法,尝试在NavigationView中放置一个列表视图并自己处理点击。
<android.support.design.widget.NavigationView
android:id="@+id/nav_drawer"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/primary_blue"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_drawer_header"
/>
<ListView
android:id="@+id/nav_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="@drawable/nav_selected_item"
android:layout_marginTop="@dimen/drawer_header_height"
>
</ListView>
</NavigationView>