Set a specific color for a specific item in the navigation drawer [duplicate]












1
















This question already has an answer here:




  • Change background color of single specific menu items of navigationView

    4 answers




Currently i want to set a specific color for one of my item in the navigation drawer:



here is my code:



Menu menuNav= mNavigationView.getMenu();
MenuItem nav_item2 = menuNav.findItem(R.id.drawer_pay).setIconTintList(ContextCompat.getColorStateList(
mNavigationView.getContext(),
R.color.background_gray));


but im receiving this kind of error:



 java.lang.NoSuchMethodError: No interface method setIconTintList(Landroid/content/res/ColorStateList;)Landroid/view/MenuItem; in class Landroid/view/MenuItem; or its super classes (declaration of 'android.view.MenuItem' appears in /system/framework/framework.jar:classes2.dex)









share|improve this question













marked as duplicate by Nilesh Rathod android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 8:31


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    1
















    This question already has an answer here:




    • Change background color of single specific menu items of navigationView

      4 answers




    Currently i want to set a specific color for one of my item in the navigation drawer:



    here is my code:



    Menu menuNav= mNavigationView.getMenu();
    MenuItem nav_item2 = menuNav.findItem(R.id.drawer_pay).setIconTintList(ContextCompat.getColorStateList(
    mNavigationView.getContext(),
    R.color.background_gray));


    but im receiving this kind of error:



     java.lang.NoSuchMethodError: No interface method setIconTintList(Landroid/content/res/ColorStateList;)Landroid/view/MenuItem; in class Landroid/view/MenuItem; or its super classes (declaration of 'android.view.MenuItem' appears in /system/framework/framework.jar:classes2.dex)









    share|improve this question













    marked as duplicate by Nilesh Rathod android
    Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 15 '18 at 8:31


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      1












      1








      1









      This question already has an answer here:




      • Change background color of single specific menu items of navigationView

        4 answers




      Currently i want to set a specific color for one of my item in the navigation drawer:



      here is my code:



      Menu menuNav= mNavigationView.getMenu();
      MenuItem nav_item2 = menuNav.findItem(R.id.drawer_pay).setIconTintList(ContextCompat.getColorStateList(
      mNavigationView.getContext(),
      R.color.background_gray));


      but im receiving this kind of error:



       java.lang.NoSuchMethodError: No interface method setIconTintList(Landroid/content/res/ColorStateList;)Landroid/view/MenuItem; in class Landroid/view/MenuItem; or its super classes (declaration of 'android.view.MenuItem' appears in /system/framework/framework.jar:classes2.dex)









      share|improve this question















      This question already has an answer here:




      • Change background color of single specific menu items of navigationView

        4 answers




      Currently i want to set a specific color for one of my item in the navigation drawer:



      here is my code:



      Menu menuNav= mNavigationView.getMenu();
      MenuItem nav_item2 = menuNav.findItem(R.id.drawer_pay).setIconTintList(ContextCompat.getColorStateList(
      mNavigationView.getContext(),
      R.color.background_gray));


      but im receiving this kind of error:



       java.lang.NoSuchMethodError: No interface method setIconTintList(Landroid/content/res/ColorStateList;)Landroid/view/MenuItem; in class Landroid/view/MenuItem; or its super classes (declaration of 'android.view.MenuItem' appears in /system/framework/framework.jar:classes2.dex)




      This question already has an answer here:




      • Change background color of single specific menu items of navigationView

        4 answers








      android navigation-drawer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 8:13









      netflix spotifynetflix spotify

      587




      587




      marked as duplicate by Nilesh Rathod android
      Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 8:31


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Nilesh Rathod android
      Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 8:31


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1














          First Way



          try using:



          app:itemIconTint="@color/color_pink"  //selected icon color
          app:itemTextColor="@color/color_pink" //selected text color
          app:itemBackground="@color/color_gray"


          For your NavigationView



          <android.support.design.widget.NavigationView
          android:id="@+id/navigation_drawer"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:headerLayout="@layout/header_layout"
          app:itemIconTint="@color/color_pink"
          app:itemTextColor="@color/color_pink"
          app:itemBackground="@color/color_gray"
          app:menu="@menu/menu_drawer" />


          Second Way



          For programetically change use:



          navigationView.setItemTextColor(ColorStateList1);
          navigationView.setItemIconTintList(ColorStateList2);


          Define ColorStateList1 and ColorStateList2 as:



          For Navigation View Item 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList1 = new ColorStateList(state, color);


          For Navigation View Item Icon 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList2 = new ColorStateList(states, colors);





          share|improve this answer
























          • This will change the color of all item in the navigation drawer, i need to be specific.

            – netflix spotify
            Nov 15 '18 at 9:13


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          First Way



          try using:



          app:itemIconTint="@color/color_pink"  //selected icon color
          app:itemTextColor="@color/color_pink" //selected text color
          app:itemBackground="@color/color_gray"


          For your NavigationView



          <android.support.design.widget.NavigationView
          android:id="@+id/navigation_drawer"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:headerLayout="@layout/header_layout"
          app:itemIconTint="@color/color_pink"
          app:itemTextColor="@color/color_pink"
          app:itemBackground="@color/color_gray"
          app:menu="@menu/menu_drawer" />


          Second Way



          For programetically change use:



          navigationView.setItemTextColor(ColorStateList1);
          navigationView.setItemIconTintList(ColorStateList2);


          Define ColorStateList1 and ColorStateList2 as:



          For Navigation View Item 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList1 = new ColorStateList(state, color);


          For Navigation View Item Icon 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList2 = new ColorStateList(states, colors);





          share|improve this answer
























          • This will change the color of all item in the navigation drawer, i need to be specific.

            – netflix spotify
            Nov 15 '18 at 9:13
















          1














          First Way



          try using:



          app:itemIconTint="@color/color_pink"  //selected icon color
          app:itemTextColor="@color/color_pink" //selected text color
          app:itemBackground="@color/color_gray"


          For your NavigationView



          <android.support.design.widget.NavigationView
          android:id="@+id/navigation_drawer"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:headerLayout="@layout/header_layout"
          app:itemIconTint="@color/color_pink"
          app:itemTextColor="@color/color_pink"
          app:itemBackground="@color/color_gray"
          app:menu="@menu/menu_drawer" />


          Second Way



          For programetically change use:



          navigationView.setItemTextColor(ColorStateList1);
          navigationView.setItemIconTintList(ColorStateList2);


          Define ColorStateList1 and ColorStateList2 as:



          For Navigation View Item 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList1 = new ColorStateList(state, color);


          For Navigation View Item Icon 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList2 = new ColorStateList(states, colors);





          share|improve this answer
























          • This will change the color of all item in the navigation drawer, i need to be specific.

            – netflix spotify
            Nov 15 '18 at 9:13














          1












          1








          1







          First Way



          try using:



          app:itemIconTint="@color/color_pink"  //selected icon color
          app:itemTextColor="@color/color_pink" //selected text color
          app:itemBackground="@color/color_gray"


          For your NavigationView



          <android.support.design.widget.NavigationView
          android:id="@+id/navigation_drawer"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:headerLayout="@layout/header_layout"
          app:itemIconTint="@color/color_pink"
          app:itemTextColor="@color/color_pink"
          app:itemBackground="@color/color_gray"
          app:menu="@menu/menu_drawer" />


          Second Way



          For programetically change use:



          navigationView.setItemTextColor(ColorStateList1);
          navigationView.setItemIconTintList(ColorStateList2);


          Define ColorStateList1 and ColorStateList2 as:



          For Navigation View Item 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList1 = new ColorStateList(state, color);


          For Navigation View Item Icon 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList2 = new ColorStateList(states, colors);





          share|improve this answer













          First Way



          try using:



          app:itemIconTint="@color/color_pink"  //selected icon color
          app:itemTextColor="@color/color_pink" //selected text color
          app:itemBackground="@color/color_gray"


          For your NavigationView



          <android.support.design.widget.NavigationView
          android:id="@+id/navigation_drawer"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          app:headerLayout="@layout/header_layout"
          app:itemIconTint="@color/color_pink"
          app:itemTextColor="@color/color_pink"
          app:itemBackground="@color/color_gray"
          app:menu="@menu/menu_drawer" />


          Second Way



          For programetically change use:



          navigationView.setItemTextColor(ColorStateList1);
          navigationView.setItemIconTintList(ColorStateList2);


          Define ColorStateList1 and ColorStateList2 as:



          For Navigation View Item 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList1 = new ColorStateList(state, color);


          For Navigation View Item Icon 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.BLUE,
          Color.WHITE,
          Color.WHITE
          };

          ColorStateList ColorStateList2 = new ColorStateList(states, colors);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 8:30









          Utkarsh SrivastavaUtkarsh Srivastava

          130111




          130111













          • This will change the color of all item in the navigation drawer, i need to be specific.

            – netflix spotify
            Nov 15 '18 at 9:13



















          • This will change the color of all item in the navigation drawer, i need to be specific.

            – netflix spotify
            Nov 15 '18 at 9:13

















          This will change the color of all item in the navigation drawer, i need to be specific.

          – netflix spotify
          Nov 15 '18 at 9:13





          This will change the color of all item in the navigation drawer, i need to be specific.

          – netflix spotify
          Nov 15 '18 at 9:13





          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues