ImageButton does not display a particular drawable

蓝咒 提交于 2019-12-01 15:33:10
abikov


Do you still have the problem. I had a similar bug - a particular drawable was not being displayed, no matter in what ImageView.
Is it the case that your image is the first (alphabetically) in the drawable folder? For some strange reason there is a problem with the first drawable, i "solved" my problem by adding a dummy drawable in first place. Still I'm very curious where the actual problem is.

Hope that helps! And I'm looking forward for any further explanations :)

I can confirm adding a dummy image which displays first alphabetically is a fix.

I had an image (titled about.png so of course near the top of the drawable folder) which was not displaying when the test device used was mdpi.

In my case, though, the image was not the first in the directory. I actually had an image which alphabetically displayed first called about_icon.png - which oddly was displaying fine. Additionally, the hdpi version of the image was displaying fine within an hdpi device.

I added a dummy placeholder image called "aaaa.png" and now the mdpi about image displays fine in device.

Very strange, and honestly a pretty lousy bug.

QuartZ

Try to use android:src="@drawable/my_resource", instead of app:srcCompat="@drawable/my_resource".

This post is fairly old however I was experiencing a similar issue. Running 4.4.2 my imagebutton's would show some images correctly however others it would change. For example my white "ic_camera.png" would look like this....

What appeared to randomly turn images into their dark counter part.(I double and tripple checked that I put the right color in) All images came from the Android Icon pack. I tried deleting and copying back all images multiple times to no avail. Finally I just changed the naming convention, dropping all of the "ic" and "_" so that the images where all simple words and lower case. ie... "camera.png", "upload.png", and "newimage.png"

BINGO!

Very strange but a simple fix. Hope this helps someone else!

Cheers!

For anyone coming to this question and the answer does not work, your image size might not cater to the devices target size... click here to get the right sizes.

For me it was a different issue. The images did show on nexus4 and nexus5 but not nexus3. I scaled down the images from 2000px width to 1000px width and worked like a charm.

When you do it in DESIGN PANEL you get something like this:

<ImageButton
        android:id="@+id/translate_button"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:srcCompat="@drawable/translate_button"/>

Change the last line manually into:

<ImageButton
        android:id="@+id/translate_button"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/translate_button"/>

It worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!