我正在我的应用程序上使用Nav抽屉.我已经制作了导航抽屉#000000(黑色)的背景.每当我选择任何项目时,文本的文本颜色从#E44F50(胡萝卜红色)变为黑色但我无法更改所选项目的背景颜色.我想要的是将所选项目的背景颜色从黑色更改为胡萝卜红色.
这是我的应用程序的github链接 -
https://github.com/manmeet-22/NewsSnips-app.git
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimary"
app:headerLayout="@layout/header"
app:itemIconTint="@drawable/drawer_item" //changing text color
app:itemTextAppearance="@style/TextAppearance20"
app:itemTextColor="@color/drawer_item"
app:itemBackground="@drawable/drawer_selected_item" //trying to change backgroundcolor the same way
app:menu="@menu/drawer"
tools:context="com.androidexample.newssnips.app.NavigationDrawerFragment"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
在这个我尝试改变背景颜色,就像我为文本做的,但我的应用程序崩溃.
这是我的drawer_selected_item.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_selected="true"/>
<item android:color="@android:color/transparent"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我的drawer_item.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorPrimary" android:state_checked="true" />
<item android:color="@color/colorAccent" />
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我的MainActivity.java:
navigationView = (NavigationView) findViewById(R.id.navigation_view);
navigationView.setItemIconTintList(null);
Menu menu = navigationView.getMenu();
//For chnaging the textColor and textSize of group's Name ie. Category
MenuItem categoryName= menu.findItem(R.id.categoryGroup);
SpannableString …Run Code Online (Sandbox Code Playgroud) android ×1