27

So I'm developing using a Samsung Note 2 device and for some reason when I create this drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<corners android:radius="5dp" />

<stroke
    android:width="1dp"
    android:color="@color/grey_light" />
</shape>

and apply it as a background to a LinearLayout, it makes the background black,

If I remove the background attribute of the LinearLayout altogether it stays transparent, only when I apply a drawable to it does it turn black.

but if I add

<solid android:color="@android:color/transparent" />

to the top of the drawable XML, it removes the black.

Now I know devices can have their own default themes but this seems like weird behaviour, is there any way I could get rid of it (/default the background to transparent) so that I don't have to add this to more of my drawables?

Note: it works fine on Nexus 7, HTC One, its only on Samsung devices that this happens.

kassim
  • 3,880
  • 3
  • 26
  • 27
  • Yes, you will need to add that to all of your shape drawables to work around Samsung's bug. – alanv Jan 28 '14 at 09:17
  • Seems it's not a bug in Samsung devices. Have You tried to fix it with your app/activity theme background? – sandrstar Jan 29 '14 at 10:22
  • How is your `"@color/grey_light"` defined? – ozbek Jan 29 '14 at 13:36
  • @shoerat in my values/colors.xml file as `#dfdfe0` – kassim Jan 29 '14 at 14:18
  • 1
    @sandrstar in what way? In the theme I've tried setting `android:background` and that does nothing. – kassim Jan 29 '14 at 14:23
  • @kmg, try setting the color in `argb` format. e.g., `#b3dfdfe0` – ozbek Jan 29 '14 at 14:47
  • 1
    @shoerat I think you're not understanding the issue. The grey_light stroke is coming through fine. The issue is that a solid black is being applied to the background of the drawable unless I apply the `` as transparent – kassim Jan 30 '14 at 10:40
  • 3
    Working around bugs in Touchwiz is like 88% of an Android developer's job. :/ – Kevin Coppock Jan 31 '14 at 02:21
  • I am facing the same problem on the emulator - Genymotion Sony Xperia Z and Gemnymotion Sony Xperia S. Is there perhaps a bug in Android itself? – Tash Pemhiwa Apr 09 '14 at 13:56
  • I think its an issue introduced by 3rd party manufacturers having defaults changed. I don't think there's much to do other than to use workarounds. Would be great if there was a value in the theme we could override. – kassim Apr 09 '14 at 14:33
  • 2
    Yesss this is great. Also, some HTC devices have the same problem. – yarian Jun 04 '14 at 21:04
  • It does it on the htc RAZR HD. – user1998494 Jun 15 '15 at 12:09
  • Related - https://stackoverflow.com/questions/18852709/xml-drawable-having-different-behavior-on-4-3-and-4-1-2 – Vadim Kotov Mar 21 '19 at 08:56

1 Answers1

18

I ran into this a couple of months ago. To the best of my knowledge, Samsung changed something in Android's code so now you have to define the solid tag. Just add the solid tag to your drawables.

dandc87
  • 1,096
  • 5
  • 7