Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawable not showing up

I have a fairly simple xml file that has an image button in it. The image shows up fine on the Graphical Layout xml designer, shows up fine when I run a development build, but as soon as I create the signed apk file and run it, the image no longer shows up. It's just an empty button. I can't think of a reason why, any ideas? The xml file looks like this:

<?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" />

    <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" />

    <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" />

        <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
            android:id="@+id/navigation_cancel_button"
            android:layout_width="75dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@string/cancel" />
    </LinearLayout>
</LinearLayout>

The image @drawable/chapter_select is a fairly small (41*41) png file that is in the res/drawable folder.

like image 382
odiggity Avatar asked Sep 19 '11 17:09

odiggity


2 Answers

Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't show up. Added a dummy image called aaaa.png to the drawable folder and problem was solved. Found the answer here: ImageButton does not display a particular drawable

like image 199
odiggity Avatar answered Sep 21 '22 12:09

odiggity


One of the reason is:

If you are using Vector file as a drawableLeft or drawableRight (or drawableStart or drawableEnd) in layout.xml, then you have to use androidx.appcompat.widget.AppCompatButton (formerly android.support.v7.widget.AppCompatButton) instead of Button.

Simple View like Button or Textview doesn't support Vector file as a drawableLeft or drawableRight (or drawableStart or drawableEnd) in my case.

like image 45
Tejas Pandya Avatar answered Sep 19 '22 12:09

Tejas Pandya