Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用srcCompat时,ImageButton不会显示图像_Java_Android_Xml - Fatal编程技术网

Java 使用srcCompat时,ImageButton不会显示图像

Java 使用srcCompat时,ImageButton不会显示图像,java,android,xml,Java,Android,Xml,我的问题是,有两个按钮显示本地图像,但它不渲染,你知道怎么做吗 列表视图中项目的XML文件: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-

我的问题是,有两个按钮显示本地图像,但它不渲染,你知道怎么做吗

列表视图中项目的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">

    <TextView
        android:id="@+id/nfi_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="13dp"
        android:text="TextView"
        android:textColor="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nfi_name"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintTop_creator="1" />

    <TextView
        android:id="@+id/nfi_timestamp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        android:text="TextView"
        android:textColor="@color/colorPrimary"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toRightOf="@+id/nfi_name"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/nfi_btnLike"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="0dp"
        app:layout_constraintRight_toLeftOf="@+id/nfi_flags"
        app:layout_constraintTop_toTopOf="@+id/nfi_btnFlag"
        app:srcCompat="@mipmap/ic_rock_on" />

    <ImageButton
        android:id="@+id/nfi_btnFlag"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginRight="12dp"
        android:layout_marginTop="-17dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nfi_status"
        app:srcCompat="@mipmap/ic_stop" />

    <TextView
        android:id="@+id/nfi_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:text="TextView"
        android:textColor="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/nfi_likes"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="8dp"

        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/circle"
        android:gravity="center"
        android:text="1"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/nfi_btnLike"
        app:layout_constraintTop_toTopOf="@+id/nfi_btnLike" />

    <TextView
        android:id="@+id/nfi_flags"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/circle"
        android:gravity="center"
        android:text="2"
        app:layout_constraintRight_toLeftOf="@+id/nfi_btnFlag"
        app:layout_constraintTop_toTopOf="@+id/nfi_btnFlag" />
</android.support.constraint.ConstraintLayout>


使用的图像是开源PNG表情图片,Web没有关于此问题的准确信息

使用attribute
app:src=“YOUR\u DRAWABLE”
而不是
app:srcCompat=“YOUR\u DRAWABLE”


FYI,始终将图像资源放在
drawable
文件夹中,而不是
mipmap
mipmap
仅用于启动器图标。

app:srccomat
在中定义,因此您必须使用
android.support.v7.widget.AppCompatImageButton
而不是
ImageButton

如果您不需要AppCompat库中可用的功能,请保留您的
ImageButton
,并使用
android:src
属性(
setImageResource
方法是此方法的Java版本)



正如@Ferdous Ahamed所指出的,这些图标应该放在一个
可绘制的
文件夹中,而不是
mipmap
文件夹中,后者只用于应用程序启动图标。

链接的
活动是否扩展
AppCompatActivity
?使用
android:src=“@mipmap/ic\u rock\u on”
而不是
app:srcompat>=“@mipmap/ic_rock_on”
@GaëtanMaisse是的,我觉得他在使用奇怪的标签@tahsinRupam@tahsinRupam很好,谢谢你,如果你使用AndroidX,一定要使用
AndroidX.appcompat.widget.AppCompatImageButton