2016-08-03 40 views
0

我有我的主要活动中导航视图,并有一些项目,问题是,当我点击项目项目名称字段获取充满蓝色background.How我可以解决导航在Android中单击时查看背景蓝色的项目封面?

代码: -

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

其配置在其样式文件不在这里显示您的'styles.xml'文件? –

+0

我添加了样式文件kinldy视图 – Nitin

+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 /彩色

//创建后file 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>