0

I have an app that has buttons with background images that I specify in the layout. For mdpi and up it works fine and you can see the images. But I recently started tested on a small device and saw the backgrounds only show black. I then checked the screen size (small) which I cater for and also checked the density, which I saw in this case is ldpi. So I rescaled the mdpi images to 36x36 and created a mipmap-ldpi folder. Android studio sees it in design time but for some reason it is not picked up at runtime. So I Googled around and saw that I might have to add them manually via Android Studio. So I created a New Resource Directory where I specified the density as ldpi as below :

Add new Resource directory

I then for each Icon added a new file with the same name and selected the ldpi folder as below :

And select ldpi directory :

select mipmap ldpi directory

I then entered the same name as it is with all the other densities for each icon / image.

After all this I still get black background so I thought let me try and assign the background programmatically. That then works. Can anyone help me with why it will not work when specifying it in the layout file. I have a layout file specifically for small screens. Must I specify density as well ?

Apologies for the images. I see I cannot embed yet because my reputation is too low.

Update 1 :

Moved all the icons to Drawables as recommended and it was still doing it. Read other articles where LDPI is not really supported anymore and then answered the question as to make the problem go away by not supporting devices with LDPI density. But the next day then picked the same problem up on a old S2 with HPDI density. So it is possibly not a LDPI problem anymore until proven otherwise. Hopefully we will find the problem and get it fixed.

  • 1
    Place your icons in drawable-lpi, drawable-hdpi etc. mipmap- is used for app icon only http://stackoverflow.com/a/28065664/343679 – Sharjeel Jun 28 '16 at 11:59
  • @Sharj , thanks for getting back to me. I have done that now according to the advice that Akeshwar gave me but I am still getting the same result. Any ideas ? – Willie Botha Jun 28 '16 at 15:09

2 Answers2

2

The mipmap directories are used to store the launcher icons. They are not used inside the app, but at the home screen and the app listing.

The reason is, when a resource from drawable-directory is requested, a bitmap is chosen from the folder that matches the current density. But, when you use the mipmap drawable, the launcher may choose an icon from a different folder (usually a size-up). That's why you're not seeing the ldpi icon.

Some launchers actually display the icons larger than they were intended. Therefore, using the mipmap for launchers helps in this.

Also check this link out.

SUMMARY: use drawables for icons used inside the app and mipmap for the launcher icon of the app.

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
  • Hi @Akeshwar. Thanks for responding. I moved all the icons to drawable and changed all the references to drawable. It was still doing it. So I selected Invalidate Caches / Restart ... and tried again but the buttons are still black. Can you perhaps think why it is then still doing it ? – Willie Botha Jun 28 '16 at 14:47
  • Ideally, it should've worked. But since it didn't, you can try adding the icons as an Image Assets again from scratch. (In the side-navigation, click open the `res` folder. Then right click on drawable folder -> New -> Image Asset -> Action Bar and Tab icons. Asset type: Image -> Next -> Finish). Update if that works. – Akeshwar Jha Jun 28 '16 at 15:30
  • Hi @Akeshwar. Thanks for responding. I have tried that before but Asset Studio only adds from mdpi up. Then I still with the same problem again to add the ldpi folder and get same result. I have also come upon a couple of articles since yesterday that indicates that ldpi support have been stopped. This is one of them http://stackoverflow.com/questions/16281570/android-low-resolution-ldpi-icons-icon-set-generator. And also on the Google Dashboards they indicate that 2.2 % of devices using Google Play still supports ldpi so I am going to take out ldpi support. Thanks for the support. – Willie Botha Jun 29 '16 at 12:31
0

Apologies. I asked my question incorrectly. I assumed it was the icons but I neglected to mention I call the icons from Layer-List drawables. Turns out Layer-List draws black on some devices that runs Android 4.0 and 4.1 if you do not explicitly mention transparent as a color. I can now see all icons from ldpi up.

Thanks for your assistance. Reference link : Android xml layer-list not displayed correctly on some devices

Community
  • 1
  • 1