0

I am using the normal way to setup vector icons in my ImageView in android . In some devices the icons are not visible , blank spaces comes over there, don't know why happening. This is happening in android pie devices only

These are some of the codes that i used to setup my icons. Icons are perfectly showing in debug device , but after release some devices creating problems.

<LinearLayout 
 android:layout_width="match_parent"
  android:padding="5sp"
  android:gravity="center"
  android:id="@+id/home_dr"
  android:layout_marginBottom="5sp"
  android:orientation="horizontal"
  android:layout_height="50sp">

<ImageView android:layout_width="50sp"
   android:padding="13sp"
   android:gravity="center"
   android:tint="@color/white"
   android:src="@drawable/ic_home"
   android:layout_height="50sp"/>

<TextView 
  android:layout_width="match_parent"
  android:layout_marginStart="10sp"
  android:text="Home"
  android:textColor="@color/white"
  android:textStyle="bold"
  android:gravity="center|start"
  android:layout_height="match_parent"/>
</LinearLayout>

Hare are some of the image you can understand well

Android
  • 1,420
  • 4
  • 13
  • 23
VikasSharmalp
  • 492
  • 1
  • 6
  • 16

2 Answers2

2

add this in your apps buil.gradle and inside defaultConfig tag:

vectorDrawables.useSupportLibrary = true

and then use AppCompatImageView with app:srcCompat. like this:

            <android.support.v7.widget.AppCompatImageView
           android:layout_width="50sp"
                   android:padding="13sp"
                   android:gravity="center"
                   android:tint="@color/white"
                   app:srcCompat="@drawable/ic_home"
                   android:layout_height="50sp" />
Payam Asefi
  • 2,677
  • 2
  • 15
  • 26
  • thanks to all but this doesnt work. Could this be the issue of android studio outdated version? or phone specific issue? – VikasSharmalp Jun 20 '19 at 07:28
1

In case of vector icons , your suppose to set them as srcCompact instead of src in image view .

app:srcCompat="@drawable/your_vector_name"

and in your build.gradle , check if you have enabled the vector drawable .

android {
defaultConfig {
    vectorDrawables.useSupportLibrary = true
}
}

For API Level 21 suppory , add this in you activity AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

Mini Chip
  • 949
  • 10
  • 12