Android Question Alpha channel

DPaul

Active Member
Licensed User
Longtime User
Hi,

With labels, i can set color, text, textcolor...etc.
But i would like to vary the alpha channel.
I seem to be able to do that in the designer, but not at runtime ?

Any thoughts ?

(Edit : other than giving the whole 4 ARGB params)

thx,
Paul
 
Last edited:

DPaul

Active Member
Licensed User
Longtime User
Hi,

My "edit" is exacly that.

It would be simpler if one could say directly:
Label.alpha = 25
or even label.color.alpha = ...

The reason being that
Label.color = colors.lightgray ( i have no clue what the B4A rgb values are)
If i want to make exactly the same color as the standard colors. how can i find out easily?

Unless you are going to tell me that B4A follows the HTML coding exactly.
Darkgrey would then be 169,169,169

:)
Paul
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2018-08-17_08.42.35.png


Cross platform solution:

B4X:
Sub Globals
   Private Label1 As Label
   Private Label2 As Label
   Private Label3 As Label
   Private Label4 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   MakeViewBackgroundTransparent(Label1, 50)
   MakeViewBackgroundTransparent(Label2, 100)
   MakeViewBackgroundTransparent(Label3, 150)
   MakeViewBackgroundTransparent(Label4, 250)
End Sub

Private Sub MakeViewBackgroundTransparent(View As B4XView, Alpha As Int)
   Dim clr As Int = View.Color
   If clr = 0 Then
       Log("Cannot get background color.")
       Return
   End If
   View.Color = Bit.Or(Bit.And(0x00ffffff, clr), Bit.ShiftLeft(Alpha, 24))
End Sub
Depends on XUI library.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
OK, this opens up new possibilities, and simplifies my coding for an unexpected reason.
I vary alpha and color at the same time.
But given a colored back panel, the change in alpha by itself causes a color shift that is useful for my puposes.

Helpful if you are making a "heat map" that shows local density of events in a given area.

thx,
Paul
 
Upvote 0
Top