我有这样的布局:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"/>
</android.support.v4.widget.DrawerLayout>
我以编程方式添加了一些像这样的项目:
navigationView = (NavigationView)ControllerParams.activity.findViewById(R.id.nav_view);
drawerMenu = navigationView.getMenu();
MenuItem menuItem1 = drawerMenu.add("1");
MenuItem menuItem2 = drawerMenu.add("2");
MenuItem menuItem3 = drawerMenu.add("3");
MenuItem menuItem3 = drawerMenu.add("4");
如何以编程方式更改第三个元素的背景颜色?
谢谢