Android Question Semitransparent colorDrawables with solid borders?

JordiCP

Expert
Licensed User
Longtime User
Hi,

I am filling a panel background with two colorDrawables, the first with COLOR_EXT as the external border and the second with COLOR_IN inside the first

My approach to do this is
B4X:
Dim cv as canvas
cv.initialize(myPanel)

Dim cd as ColorDrawable
cd.initialize(COLOR_EXT,radius)
Dim Rect1 as Rect
Rect1.initialize(0,0,W,H)
cv.DrawDrawable(cd,Rect1)

Dim cd as ColorDrawable
cd.initialize(COLOR_IN,radius)
Dim Rect1 as Rect
Rect1.initialize(2,2,W-2,H-2)
cv.DrawDrawable(cd,Rect1)

When COLOR_IN is opaque, this is the inner panel color.
Also if it has alpha, then it composes with COLOR_EXT.

But, is there any way to make COLOR_EXT disappear from the inner drawable when COLOR_IN has alpha? I know how to do it with normal DrawColor, but not with a ColorDrawable, and I would like to keep the round borders. Is it possible?



Thanks!
 

klaus

Expert
Licensed User
Longtime User
Shouldn't (2,2,W-2,H-2) be (2,2,W-4,H-4) for the rectangles ?
Have you tried to to use Color.Transparent for COLOR_EXT when COLOR_IN has alpha?
Or you could try to set the rectangle to (0,0,W,H) instead of (2,2,W-2,H-2) when COLOR_IN has alpha.
In (2,2,W-2,H-2) you should use dip values (2dip,2dip,W-4dip,H-4dip).
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Shouldn't (2,2,W-2,H-2) be (2,2,W-4,H-4) for the rectangles ?
Have you tried to to use Color.Transparent for COLOR_EXT when COLOR_IN has alpha?
Or you could try to set the rectangle to (0,0,W,H) instead of (2,2,W-2,H-2) when COLOR_IN has alpha.
In (2,2,W-2,H-2) you should use dip values (2dip,2dip,W-4dip,H-4dip).

Hi Klaus,

Well, it was just an example. What I am looking for is to get a panel with a solid color border of a given width , but "empty" inside (and still rounded corners)

So my approach (but don't know if it is possible) was to draw first a solid color to the whole panel, and then another with smaller dimensions inside and see if there was any way to set the XferMode for a colordrawable so that the later one would clear what there is under it.

Thanks
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
The easiest way to know if it's possible is to test it.
I would need to test it too to know it.
I thought you had tested the code you posted.

Yes, it is tested (but did not a copy/paste, that's all, sorry for the misunderstanding ) but unfortunately, does not do what I am after. It composes COLOR_IN over COLOR_EXT, even if COLOR_IN is Colors.transparent.

The behaviour is different than when you call Canvas.drawColor( Colors.Transparent) but it is (I suppose) because this case is handled differently as I have just read here , but I suppose this behaviour isn't the same when canvas.DrawDrawable is used

Thank you anyway.
 
Upvote 0
Top