我在我的主要活动中有一个导航视图并且有一些项目,问题是当我点击项目项目名称字段时会填充蓝色背景。我如何解决该问题
代码: -
NavigationView m_Navigation = (NavigationView) findViewById(R.id.nav_view);
m_Navigation.setNavigationItemSelectedListener(this);
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_wallet) {
// Handle the camera action
Intent wallet = new Intent(this, CMyWalletScreen.class);
startActivity(wallet);
} else if (id == R.id.referandEarn) {
Intent refer = new Intent(this, CReferAndEarnScreen.class);
startActivity(refer);
} else if (id == R.id.myProfile) {
Intent profile = new Intent(this, CMyProfile.class);
startActivity(profile);
} else if (id == R.id.setting) {
Intent setting = new Intent(this, CSettingScreen.class);
startActivity(setting);
} else if (id == R.id.LogOut) {
showdialog();
}
m_Drawer.closeDrawer(GravityCompat.START);
return true;
}
样式文件: -
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary</item>
<item name="colorAccent">@color/accent</item>
<item name="android:statusBarColor" tools:ignore="NewApi">@color/primary_dark</item>
</style>
答案 0 :(得分:0)
我认为你的问题已解决:
您的xml文件处于更改
//在标题
中添加此行xmlns:app="http://schemas.android.com/apk/res-auto"
//在导航视图中添加此代码后
<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:itemBackground="@color/drawer_item" />
//创建文件夹res / color
之后//创建文件res / color / drawer_item.xml
之后//在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"
android:drawable="#0098D9"/> //your color code
<item
android:color="@android:color/white"
android:drawable="@android:color/white"/>
</selector>