Search code examples
android-imagebutton

ImageButton doesn't shows the image


I have a problem running with the ImageButton. It does not show the image of the drawable folder, it shows a small gray rectangle.

Demomento I put only the code of the layout of the activity because by clicking on the rectangle that comes out if it does the action.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="mdl.acp.Menu">


        <Spinner
                    android:id="@+id/numeroGru"
                    android:layout_width="240dp"
                    android:layout_height="25dp"
                    android:layout_alignStart="@+id/textView6"
                    android:layout_below="@+id/textView6"
                    android:layout_marginLeft="35dp"
                    android:layout_marginTop="25dp"
                    tools:layout_editor_absoluteX="82dp"
                    tools:layout_editor_absoluteY="161dp" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/textView6"
            android:layout_below="@+id/numeroGru"
            android:layout_marginTop="46dp"
            android:text="@string/seleccionaDtAct"
            android:textColor="@color/colorPrimary"
            android:textSize="18sp"
            android:textStyle="bold"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="251dp" />

                <Spinner
                    android:id="@+id/deporte"
                    android:layout_width="240dp"
                    android:layout_height="25dp"
                    android:layout_alignStart="@+id/textView7"
                    android:layout_below="@+id/textView7"
                    android:layout_marginLeft="35dp"
                    android:layout_marginTop="25dp"
                    tools:layout_editor_absoluteX="25dp"
                    tools:layout_editor_absoluteY="338dp"/>

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/relativeLayout"
            android:layout_marginStart="28dp"
            android:layout_marginTop="23dp"
            android:text="@string/seleccionaAct"
            android:textColor="@color/colorPrimary"
            android:textSize="18sp"
            android:textStyle="bold"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="84dp" />

        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@color/colorPrimaryDark"
            android:layout_alignParentEnd="true">

                <TextView
                    android:id="@+id/textView8"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:text="@string/nuevoAct"
                    android:textAlignment="center"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:textStyle="bold"
                    tools:text="@string/nuevoAct" />
        </RelativeLayout>

        <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="40dp"
            android:elevation="0dp"
            app:srcCompat="@drawable/btnsig" />

</RelativeLayout>

The image is a png file whose dimesiones are 80x80 (32 bit color) 5.1k. I do not know if the problem will have to do with some attribute of the layout of width or height that has as value match parent.

Thanks.


Solution

  • Try this:

    Set android:src="@drawable/btnsig" instead of app:srcCompat="@drawable/btnsig".

    This will work, just tested.