DEVANDRIN KUNI
DEVANDRIN KUNI

Reputation: 81

ImageButton wont display image when using srcCompat

My Problem is this, There's two buttons that display local images, but it doesnt render, any ideas on what to do here ??

Screen Shot

XML File for items in the list View:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/nfi_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="13dp"
        android:text="TextView"
        android:textColor="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nfi_name"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintTop_creator="1" />

    <TextView
        android:id="@+id/nfi_timestamp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        android:text="TextView"
        android:textColor="@color/colorPrimary"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toRightOf="@+id/nfi_name"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/nfi_btnLike"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="0dp"
        app:layout_constraintRight_toLeftOf="@+id/nfi_flags"
        app:layout_constraintTop_toTopOf="@+id/nfi_btnFlag"
        app:srcCompat="@mipmap/ic_rock_on" />

    <ImageButton
        android:id="@+id/nfi_btnFlag"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginRight="12dp"
        android:layout_marginTop="-17dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nfi_status"
        app:srcCompat="@mipmap/ic_stop" />

    <TextView
        android:id="@+id/nfi_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:text="TextView"
        android:textColor="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/nfi_likes"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="8dp"

        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/circle"
        android:gravity="center"
        android:text="1"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/nfi_btnLike"
        app:layout_constraintTop_toTopOf="@+id/nfi_btnLike" />

    <TextView
        android:id="@+id/nfi_flags"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/circle"
        android:gravity="center"
        android:text="2"
        app:layout_constraintRight_toLeftOf="@+id/nfi_btnFlag"
        app:layout_constraintTop_toTopOf="@+id/nfi_btnFlag" />
</android.support.constraint.ConstraintLayout>

The images used are open source PNG EMotee images,Web doesnt have accurate info on this problem

Upvotes: 2

Views: 1528

Answers (2)

Ga&#235;tan Maisse
Ga&#235;tan Maisse

Reputation: 12347

app:srcCompat is defined in AppCompat library so you have to use android.support.v7.widget.AppCompatImageButton instead of ImageButton.

If you don't need features available in AppCompat lib then keep your ImageButton and use android:src attribute (setImageResource method is the Java version of this).


As pointed out by @Ferdous Ahamed, these icons should be in a drawable folder instead of mipmap one, the latter is only used for app launcher icon.

Upvotes: 7

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21736

Use attribute app:src="YOUR_DRAWABLE" instead of app:srcCompat="YOUR_DRAWABLE".

FYI, Always put image resources in drawable folder instead of mipmap. mipmap is only for launcher icons.

Upvotes: 0

Related Questions