Android:Drawable没有显示出来

odi*_*ity 8 android image button

我有一个相当简单的xml文件,里面有一个图像按钮.图形布局xml设计器上的图像显示正常,当我运行开发版本时显示正常,但是一旦我创建了签名的apk文件并运行它,图像就不再显示了.这只是一个空按钮.我想不出有什么理由,有什么想法吗?xml文件如下所示:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navigation_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/navigation_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:text="TextView"
    android:textAppearance="?android:attr/textAppearanceLarge" >
</TextView>

<SeekBar
    android:id="@+id/navigation_seekbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_weight="1"
    android:padding="5dp" >
</SeekBar>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp" >

    <ImageButton
        android:id="@+id/part_select_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/chapter_select" >
    </ImageButton>

    <Button
        android:id="@+id/navigation_ok_button"
        android:layout_width="75dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="@string/ok" >
    </Button>

    <Button
        android:id="@+id/navigation_cancel_button"
        android:layout_width="75dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="@string/cancel" >
    </Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

该图像@drawable/chapter_select是一个相当小(41*41)的png文件,位于res/drawable文件夹中.

odi*_*ity 13

似乎这是一个android的错误,有时可绘制文件夹中的第一个图像不会显示.在drawable文件夹中添加了一个名为aaaa.png的虚拟图像,问题解决了.在这里找到答案:ImageButton不显示特定的drawable


Tej*_*dya 8

原因之一是

如果您将Vector文件用作左侧或右侧的可绘制对象,则必须使用 .

android.support.v7.widget.AppCompatButton

代替

按钮

在我的情况下,Simple View likeButton,Textview不支持Vectorfile as aDrawable left right


Kob*_*Gal 5

发生了相同的问题,并通过删除所有特殊字符解决了该问题。在我的情况下,文件名中的破折号“-”:

background-720.png => background.png