StateListDrawable

Brendon

Member
Licensed User
Longtime User
Hi All,
I've got a button with StateListDrawable enabled. On EnabledDrawable i've got an image file set with gravity set to fill. On PressedDrawable I've got the same image file with gravity set to center.
I want to change image associated with both this state with another one with same gravity.
My code is
Dim sd As StateListDrawable
sd.Initialize
sd.AddState(sd.State_Enabled, bdFiltro)
sd.AddState(sd.State_Pressed, bdFiltro)
cmdCerca.Background=sd

When I click on button first time I see my bitmap gettin small, then change to other bitmap, but when I click again on that butto my bitmap doesn't get small and continues with filling entire button space.

Does someone has a hint to help me solve this problem?

Kind regards to everyone.
 

klaus

Expert
Licensed User
Longtime User
This code does work:
B4X:
    btnBitmap.Initialize("btnBitmap")
    Activity.AddView(btnBitmap, 40dip, 260dip, 60dip, 60dip)

    ' Define a BitmapDrawable for Enabled state
    Dim bdwEnabled As BitmapDrawable
    bdwEnabled.Initialize(LoadBitmap(File.DirAssets, "btnArrowDown0.png"))
    ' Define a BitmapDrawable for Pressed state
    Dim bdwPressed As BitmapDrawable
    bdwPressed.Initialize(LoadBitmap(File.DirAssets, "btnArrowDown1.png"))
    ' 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)
    ' Set stdBitmap to button btnBitmap 
    btnBitmap.Background = stdBitmap
Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…