Parth Bhoiwala
Parth Bhoiwala

Reputation: 1322

imageView not displaying in alertDialog

I have a pop up that I populate through my custom xml. I want an icon and next to the icon, I want a switch. The custom xml looks has this code in it:

<!-- alertdialog_menu.xml -->
<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:weightSum="1"
    android:layout_marginStart="5dp"
    android:layout_marginLeft="5dp">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="32dp"
        android:layout_weight="0.10"
        app:srcCompat="@mipmap/ic_satellite_black_24dp"
        android:scaleType="fitXY"/>

    <Switch
       android:id="@+id/satelliteSwitch"
       android:layout_width="0dp"
       android:layout_height="36dp"
       android:layout_weight="0.90"
       android:text="Satellite"
       android:textSize="22sp"/>

And this below is my java code that I use to display the popup.

LayoutInflater li = LayoutInflater.from(this);
View promptsView = li.inflate(R.layout.alertdialog_menu, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(promptsView);
alertDialogBuilder.create().show();

This is what I see: enter image description here

I should see the icon imageView to the left of the satellite imageview, but instead I see empty white space.

Upvotes: 4

Views: 1344

Answers (1)

John Joe
John Joe

Reputation: 12803

You should use android:src="@mipmap/ic_satellite_black_24dp" instead of app:srcCompat="@mipmap/ic_satellite_black_24dp"

Between, place your image to drawable folder, not mipmap folder. Mipmap folder is used to place your app/launcher icons.

To know the differences , check mipmap vs drawable folders.

Upvotes: 4

Related Questions