0

The image button does not show up in my app, but the button is still clickable its click log works.

This is the button:

<ImageButton
    android:id="@+id/stopStream"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_margin="10dp"
    android:background="@drawable/cancel_btn"
    android:contentDescription="@string/stop_stream"
    android:onClick="hangup"
    android:visibility="visible" />

Android Studio does show the drawable icon and the left toolbar, so the path of the image is correct. First I thought of having a wrong z-index (I come from the web world). But there is not a real z-index to give a tag in android as far as I read. What could further cause this issue

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    tools:context="de.app.test.VideoChatActivity">

    <android.opengl.GLSurfaceView
        android:id="@+id/gl_surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" />

    <ImageButton
        android:id="@+id/stopStream"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="10dp"
        android:background="@drawable/cancel_btn"
        android:contentDescription="@string/stop_stream"
        android:onClick="hangup"
        android:visibility="visible" />

    <ImageButton
        android:id="@+id/switchCameraBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignTop="@+id/stopStream"
        android:layout_marginEnd="9dp"
        android:background="@color/transparent"
        android:contentDescription="@string/send"
        android:visibility="gone" />

    <ImageButton
        android:id="@+id/switchBtn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentEnd="true"
        android:layout_alignTop="@+id/switchCameraBtn"
        android:layout_marginEnd="9dp"
        android:background="@drawable/call_btn"
        android:contentDescription="@string/send" />

    <RelativeLayout
        android:id="@+id/drawable_mod"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:orientation="horizontal"
        android:visibility="gone">

        <ImageView
            android:id="@+id/drawing1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:scaleType="fitXY"
            android:contentDescription="@string/drawing_one" />

    </RelativeLayout>

</RelativeLayout>
2
  • Can you see the call_btn file in the drawable folder in Android Studio? Commented Oct 22, 2018 at 13:24
  • i think your cancel_btn icon is black so it's invisible on a black background Commented Oct 22, 2018 at 13:56

1 Answer 1

1

Try using src to set your icon to ImageButton, like

<ImageButton
        android:id="@+id/stopStream"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="10dp"
        android:src="@drawable/cancel_btn"
        android:background="@null"
        android:contentDescription="@string/stop_stream"
        android:onClick="hangup"
        android:visibility="visible" />

//used background="@null" to set the image button background as null to only show the icon which was set with the src.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.