Good day. I use NavigationView in my project. In the menu lines, I indicate my icons in white, but when I run the application on the emulator or device, my icons turn gray. I tried to specify a transparent background for them, but it did not help. In addition, my icon is somehow stretched. Tell me what am I doing wrong? Here is my menu:

  <item android:orderInCategory="1" android:id="@+id/menu_info" android:title="@string/info_menu" android:icon="@drawable/icon_i" android:background="@android:color/transparent" /> 

Here are the screenshots of how I want to do it and how it turns out: enter image description here

enter image description here

    1 answer 1

    Gray for them is the standard NavigationView

     mNavigationView = (NavigationView)findViewById(R.id.navigation_view); 

    Do this: mNavigationView.setItemIconTintList(null);

    And it went:

     <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@color/primary" /> <item android:state_checked="false" android:color="@android:color/white"/> </selector> 

    You can also try this: mNavigationView.setItemIconTintList(null); and

     <android.support.design.widget.NavigationView ... app:itemIconTint="@android:color/black" ... /> 

    In order for the picture not to be stretched you need to make it appropriate for each screen size, that is:

      1. drawable-xxhdpi: 144x144 2. drawable-xhdpi: 96x96 3. drawable-hdpi: 72x72 4. drawable-mdpi: 48x48 

    Start learning from here.

    • Thanks, I already figured out that the color is set to gray automatically, this helped the app:itemIconTint="@color/colorWhite" . But the question remains, why is my icon stretched? - ivanovd422
    • @ Denis422 are you loading a picture from a drawable? if so, what size is it? - iFr0z
    • @ Denis422 updated the answer - iFr0z
    • Yes, from drawable. Some icons are normally displayed, and this one is stretched. It seems that due to the size, those icons that are smaller in width just stretch .. - ivanovd422
    • @ Denis422 I was glad to help you) if the answer helped, then click on the checkbox to the left of the answer :) - iFr0z