Android 有没有办法更改导航抽屉中单个项目的背景色?

Android 有没有办法更改导航抽屉中单个项目的背景色?,android,navigation-drawer,background-color,menuitem,Android,Navigation Drawer,Background Color,Menuitem,我有一个导航抽屉菜单,如下所示: 是-您可以创建xml文件,并在导航标签中包括: <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="sta

我有一个导航抽屉菜单,如下所示:


是-您可以创建
xml
文件,并在导航标签中包括:

<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:layout_marginTop="?android:attr/actionBarSize">

        <include layout="@layout/a_main_navigation_content" />

    </android.support.design.widget.NavigationView>

a\u main\u navigation\u content.xml
中,您可以使用自定义属性创建
textView
或任何您想要的内容


您不再需要菜单项。

为了使用导航抽屉的优点和使用自定义bg,您需要编写自定义导航适配器。然后你可以膨胀任何你想要的布局。创建一个扩展
RecyclerView.Adapter
的类

如果要使用项目标记并执行此操作,作为替代方法,您可以尝试使用BackgroundColorsPanand


s、 设置跨距(新背景色跨距(颜色.红色),0,s.长度(),0)

这就是我正在做的,这不是问题所在。我想更改单个项目的背景色,但所有项目都具有相同的颜色nav_hardware=(MenuItem)menu_principal.findItem(R.id.nav_hardware);当你在navMenu中有3个文本视图时,你可以通过调用第3个文本视图的ID或Createdobject来更改其颜色。如果您使用ExpandableListView,您可以更改OnChildClickListener代码中的颜色。我找不到允许我更改项目背景颜色的内容。您仍然在以自己的方式进行操作,请使用除菜单之外的任何视图,而不是菜单,如TextView sampleNavigationText=findViewById(R.id.yourTextView);更改如下:sampleNavigationText.setTextColor(Color.RED);简言之,没那么简单。你试过这个吗?也许这会帮助你。。。!