Setting alpha using animation library

francoisg

Active Member
Licensed User
Longtime User
Hi All,

Is it possible to permanently set the alpha of an item to say 0.5 and then only once the user clicks on it it will become fully opaque?

I am using:

a.InitializeAlpha("a", 0.5, 0.5)
a.Duration = 0 'adjust your blinking speed
a.RepeatCount = 0
a.Start(btn)

i.e. Instead of blinking i want it to stay transparent until clicked on...

Regards
Francois
 

francoisg

Active Member
Licensed User
Longtime User
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?

Maybe using drawable somehow?
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
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?

Maybe using drawable somehow?

This should be possible using a Statelist Drawable, which has an alpha field. Set it to 127.
 
Upvote 0

francoisg

Active Member
Licensed User
Longtime User
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???
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
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.
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi All,

Is it possible to permanently set the alpha of an item to say 0.5 and then only once the user clicks on it it will become fully opaque?

I am using:

a.InitializeAlpha("a", 0.5, 0.5)
a.Duration = 0 'adjust your blinking speed
a.RepeatCount = 0
a.Start(btn)

i.e. Instead of blinking i want it to stay transparent until clicked on...

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).
 
Upvote 0
Top