Hi,
thank you for the reply. Is it at all possible to create dynamically (in code) a button, set the button image to display and make it (the button, with the image) say 50% transparent?
Hi,
thank you for the reply. Is it at all possible to create dynamically (in code) a button, set the button image to display and make it (the button, with the image) say 50% transparent?
Hi,
I'm using the following code but (obviously) this does not work with bitmaps:
B4X:
Dim cd As ColorDrawable
cd.Initialize(Colors.ARGB(127, 255, 128, 128), 5)
Dim sld As StateListDrawable
sld.Initialize
sld.AddState (sld.State_Disabled, cd)
sld.AddState (sld.State_Pressed, cd)
sld.AddCatchAllState (cd)
btn.Background = sld
Any suggestions on how to get it working WITH a bitmap???
Hi,
I'm using the following code but (obviously) this does not work with bitmaps:
B4X:
Dim cd As ColorDrawable
cd.Initialize(Colors.ARGB(127, 255, 128, 128), 5)
Dim sld As StateListDrawable
sld.Initialize
sld.AddState (sld.State_Disabled, cd)
sld.AddState (sld.State_Pressed, cd)
sld.AddCatchAllState (cd)
btn.Background = sld
Any suggestions on how to get it working WITH a bitmap???
You should be sure to also set sld.State_Enabled, the default button value. As for the bitmap, perhaps something using ABExtDrawing would be more akin to your liking:
B4X:
Dim ed As ABExtDrawing
Dim p As ABPaint
p.SetAlpha(127)
ed.drawBitmap
You should be able to figure out the rest of that, just be sure to use p as the paint for ed.drawBitmap. Basically just draw the bitmap loaded from an image to a new bitmap, and when drawing it use that paint to make it partially transparent. Then set the button to that bitmap.
As Erel said, you can use my AnimationPlus library to set a transparency level:
a.InitializeAlpha(myButton, 0.5, 0.5)
a.PersistAfter = True
a.Start(myButton)
Then, in the Click event:
a.InitializeAlpha(myButton, 0.5, 1)
a.Start(myButton)
This code allows to do a smooth transition from transparent to opaque. If you don't care of this transition, you can use my Accelerated Surface library. There's a function called AlterColors in the class AS_ImageUtils that allows to modify the transparency (+ hue and saturation) of a bitmap with an optimized algorithm (it can be used in real-time).