Android ImageButton不显示图像,即使它在Designer预览中可见

Gla*_*ave 5 java xml android android-studio

我正在尝试在Android Studio中创建一个图像按钮.Designer预览正确显示图像,但是当我运行App时,Button中没有图像.只是一个尽可能小的空按钮.

我尝试过的事情:

  • 将Android drawable文件夹中的图像复制到我自己的drawable文件夹中
  • 根据stackoverflow上的一些来源,由于错误而创建占位符图像会阻止文件夹中的第一个图像不显示
  • 使用不同的图像

这些都不适合我.这就像整个功能刚刚被打破.有趣的是,当我设置我想要的图像作为图像按钮的背景时,它工作正常.但它失去了它的"按钮外观",所以这对我来说不是解决方案.

<?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>
Run Code Online (Sandbox Code Playgroud)

小智 19

尝试仅使用src而不是srcCompat,看看它是否有效