【发布时间】:2017-03-18 23:34:32
【问题描述】:
我正在尝试在 Android Studio 中创建一个图像按钮。设计器预览正确显示图像,但是当我运行应用程序时,按钮中没有图像。只是一个尽可能小的空按钮。
我尝试过的事情:
- 将图像从 Android drawable 文件夹复制到我自己的 drawable 文件夹中
- 根据 stackoverflow 上的一些消息来源,由于存在错误而创建占位符图像会阻止文件夹中的第一张图像不显示
- 使用不同的图片
这些都不适合我。就像整个功能被破坏了一样。有趣的是,当我将想要的图像设置为 imagebutton 的背景时,它可以正常工作。但它失去了它的“按钮外观”,所以这对我来说不是一个解决方案。
<?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>
【问题讨论】:
标签: java android xml android-studio