B4J Question Button Image

BeneBarros

Active Member
Licensed User
Longtime User
This is a function in B4A.
Is there a way to do similar to B4J?

B4X:
Public Sub ButtonSetStateListDrawable(btnBitmap As Button, EnabledBitmap As String, PressedBitmap As String, DisabledBitmap As String)
    ' Define a bitmap for Enabled state
    Dim bdwEnabled As BitmapDrawable
    bdwEnabled.Initialize(LoadBitmap(File.DirAssets, EnabledBitmap))
    ' Define a bitmap for Pressed state
    Dim bdwPressed As BitmapDrawable
    bdwPressed.Initialize(LoadBitmap(File.DirAssets, PressedBitmap))

    ' Define a bitmap for Disabled state
    Dim bdwDisabled As BitmapDrawable
    bdwDisabled.Initialize(LoadBitmap(File.DirAssets, DisabledBitmap))

    ' Define a StateListDrawable
    Dim stdBitmap As StateListDrawable
    stdBitmap.Initialize
    Dim states(2) As Int
    states(0) = stdBitmap.state_enabled
    states(1) = -stdBitmap.state_pressed
    stdBitmap.addState2(states, bdwEnabled)
    Dim states(1) As Int
    states(0) = stdBitmap.state_enabled
    stdBitmap.addState2(states, bdwPressed)
    Dim states(1) As Int
    states(0) = stdBitmap.State_Disabled
    stdBitmap.addState2(states, bdwDisabled)

    ' Set stdBitmap to button btnBitmap
    btnBitmap.Background = stdBitmap
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can set the image with the designer:

SS-2016-10-13_09.00.47.png


Or: https://www.b4x.com/android/forum/threads/how-to-add-an-icon-to-a-button-via-code.57733/#post-363608
 
Upvote 0
Top