i am trying to create an Image Button in Android Studio. The Designer preview shows the image correctly, but when I run the App there is no image in the Button. Just an empty button as small as possible.
Things I have tried:
None of this worked for me. It is like the whole function is just broken. The interesting part is, when I set the image I want as the background of the imagebutton it works fine. But it looses its "button-appearence", so thats not a solution for me.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<org.osmdroid.views.MapView android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/search_ui"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="1dp"
android:background="@color/white"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_menu_manage"
android:id="@+id/imageButton"/>
<EditText android:id="@+id/edit_search_string"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/search_string" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="myClickHandler"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="@color/white"
android:layout_below="@id/search_ui">
<TextView
android:id="@+id/display"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text" />
</LinearLayout>
In simple words we can say, ImageButton is a button with an image that can be pressed or clicked by the users. By default it looks like a normal button with the standard button background that changes the color during different button states.
By default, an ImageButton looks like a regular Button , with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the <ImageButton> XML element or by the ImageView. setImageResource(int) method.
try using only src instead of srcCompat and see if it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With