Search code examples
androidnavigation-drawerandroid-navigationview

How to show drawable in NavigationView


I want to show a drawable icon with a circular background in NavigationView i created a circular brown background for a Image but am getting gray circular view as a result don't know why ? anyone have any idea why it is happening and how to get the desired result ?

drawable code to show icon with circular background, icon_view.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <solid android:color="#785125"/>
    </shape>
 </item>
 <item
    android:drawable="@drawable/ic_icon"
    android:bottom="20dp"
    android:left="20dp"
    android:right="20dp"
    android:top="20dp"/>
</layer-list> 

Result : enter image description here

But result in NavigationView looks like this :

enter image description here


Solution

  • I figure out the issue and the solution so posting the solution it may will help someone for drawable i reduce margin :

     <?xml version="1.0" encoding="utf-8"?>
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item>
     <shape android:shape="oval">
        <solid android:color="#785125"/>
      </shape>
      </item>
      <item
        android:drawable="@drawable/ic_action_settings"
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp"/>
      </layer-list> 
    

    and in java code making icon tint as null works

      navigationView.setItemIconTintList(null);