Android: Drawable not showing

I have a pretty simple xml file that has an image button in it. The image is displayed perfectly in the graphic designer of the xml designer, it is displayed perfectly at the start of the development assembly, but as soon as I create the signed apk file and run it, the image is no longer displayed. This is just an empty button. I can’t come up with 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" > </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> 

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

+7
source share
4 answers

It seems that this is an error with android, where sometimes the first image in a folder with the ability to transfer does not appear. A dummy image called aaaa.png was added to the selectable folder, and the problem was resolved. Found the answer here: ImageButton does not display a specific version

+12
source

try placing the image in the drawable-hdpi and drawable-mdpi folder depending on which device you are running the application on, search for images in these folders ...

But alignment means that the image should be accessible everywhere, but sometimes (depending on your manifest settings) this may not be true, I mean, you can enable compatibility mode.

also you can try dynamically at runtime to set the image to view

 iv.setImageResource(R.drawable.somethig); 
+2
source

Had the same problem and resolved it by removing all special characters. In my case, these were dashes '-' in the file name:

background-720.png => background.png .

+2
source

My situation was strange. Everything was correct until I included the FireBase Crash report in my application.

I just added a compilation of 'com.google.firebase:firebase-crash:11.0.1' and DrawableLeft disappeared . When I went through the xml, I noticed a warning (in aligned below).

So added android:drawableStart and the problem disappeared.

However, I am interested in knowing how FireBase Crash reports are related.

Using left / right attributes instead of start / end attributes Using Gravity # LEFT and Gravity # RIGHT can cause problems when creating a layout in which text flows from right to left. Use Gravity # START and Gravity # END instead.

Similarly, in the XML gravity and layout_gravity attributes, use start rather than left. For XML attributes such as paddingLeft and layout_marginLeft, use paddingStart and layout_marginStart.

NOTE. If your minSdkVersion is less than 17, you should add both the senior attributes on the left and right, as well as the new start / right attributes. On older platforms where RTL is not supported and the start / right attributes are unknown and therefore ignored, you need older ones on the left / right.

There is a separate interception check that catches this type of error. (Note: for gravity # LEFT and Gravity # START, you can use these constants even when targeting older platforms, since the start bitmask is a superset of the left bitmask. Therefore, you can use gravity = "start" rather than gravity = "left | start" .)

0
source

All Articles