与列表视图一起使用时 ImageButton 不出现

ImageButton not appearing when used with List View

所以我正在尝试使用 tweetUi 显示 Twitter 帖子,但是,图像按钮未显示在相对布局中,但如果单击一般区域,它会执行预期的操作(编辑:textview 是可见的 int虽然是相对布局)。此外,我注意到这只是与列表视图一起使用时的问题,因为对于我的其他视图,图像按钮在与照片视图和网络视图一起使用时显示在相对布局中。

<LinearLayout
    android:id="@+id/TartanDailyLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.ghsapp.TwitterAnnouncements"
    android:background="#D32E32"
    android:orientation="vertical"
    android:weightSum="9"
    android:statusBarColor="#D32E32">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0sp"
        android:layout_weight=".5">

        <TextView
            android:id="@+id/TartanDailyHeader"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#C52C33"
            android:text="Announcements"
            android:gravity="center"/>
        <ImageButton
            android:id="@+id/BackButton1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:backgroundTint="@android:color/transparent"
            android:tint="@android:color/white"
            app:srcCompat="?android:attr/actionModeCloseDrawable"
            android:onClick="onStartAction"/>

    </RelativeLayout>
    <ListView android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0sp"
        android:layout_weight="9"
        android:divider="#e1e8ed"
        android:dividerHeight="1dp"
        android:drawSelectorOnTop="false">
    </ListView>
</LinearLayout>

This is what it looks like in android studio

This is what it looks like in the emulator

像这样使用 android.support.v7.widget.AppCompatImageButton 而不是 ImageButton

<LinearLayout
    android:id="@+id/TartanDailyLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.ghsapp.TwitterAnnouncements"
    android:background="#D32E32"
    android:orientation="vertical"
    android:weightSum="9"
    android:statusBarColor="#D32E32">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0sp"
        android:layout_weight=".5">

        <TextView
            android:id="@+id/TartanDailyHeader"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#C52C33"
            android:text="Announcements"
            android:gravity="center"/>
        <android.support.v7.widget.AppCompatImageButton
            android:id="@+id/BackButton1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:backgroundTint="@android:color/transparent"
            android:tint="@android:color/white"
            app:srcCompat="?android:attr/actionModeCloseDrawable"
            android:onClick="onStartAction"/>

    </RelativeLayout>
    <ListView android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0sp"
        android:layout_weight="9"
        android:divider="#e1e8ed"
        android:dividerHeight="1dp"
        android:drawSelectorOnTop="false">
    </ListView>
</LinearLayout>

此外,请确保执行以下操作: 设置你的 build.gradle

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }  

您可以参考此了解更多详情。