Wish Some properties are writeonly !

stevel05

Expert
Licensed User
Longtime User
Setting the color of a View sets it's Background to a ColorDrawable, it's background could also potentially be GradientDrawable, a StateListDrawable or a DrawableDrawable (I don't think there are any more).

You cannot extract the color from the other three possible states as there are potentially more than one color in those drawables.

If you know that the background is a ColorDrawable you can get the color using this code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    Dim O As Object = Label1.Background
    If O Is ColorDrawable Then
        Log(GetColor(O))
    End If

End Sub
Sub GetColor(CD As ColorDrawable) As Int
    Dim JO As JavaObject = CD
    Return JO.RunMethod("getColor",Null)
End Sub
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
I'm sure there is good reason, as in this case, for the properties not being read/write. When you find one, post a new thread and someone will be able to tell you if you can access it or why you can't.
 
Top