how to add options menu items into cardview android code example

Example 1: change activity main drawer items text color programmatically android

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

	//items text color
    int[][] state = new int[][] {
            new int[] {-android.R.attr.state_enabled}, // disabled
            new int[] {android.R.attr.state_enabled}, // enabled
            new int[] {-android.R.attr.state_checked}, // unchecked
            new int[] { android.R.attr.state_pressed}  // pressed

    };

    int[] color = new int[] {
            Color.WHITE,
            Color.WHITE,
            Color.WHITE,
            Color.WHITE
    };

    ColorStateList colorStateList1 = new ColorStateList(state, color);


    //icons color
    int[][] states = new int[][] {
            new int[] {-android.R.attr.state_enabled}, // disabled
            new int[] {android.R.attr.state_enabled}, // enabled
            new int[] {-android.R.attr.state_checked}, // unchecked
            new int[] { android.R.attr.state_pressed}  // pressed

    };

    int[] colors = new int[] {
            Color.WHITE,
            Color.WHITE,
            Color.WHITE,
            Color.WHITE
    };
    ColorStateList colorStateList2 = new ColorStateList(states, colors);
    navigationView.setItemTextColor(colorStateList1);
    navigationView.setItemIconTintList(colorStateList2);

Example 2: change activity main drawer items text color android

<android.support.design.widget.NavigationView
    app:menu="@menu/drawer_view" <!-- add this line for items' text color -->
    app:itemTextColor="@color/colorWhite"> <!-- add this line for items' icons color -->

Tags:

Java Example