Android Question StateListDrawable and Button

Discussion in 'Android Questions' started by Anser, Sep 16, 2015.

  1. Anser

    Anser Well-Known Member Licensed User


    I have a button. There will be 3 states for the button.

    1. Enabled
    2. Disabled
    3. Pressed

    When I load the activity, initially the button will be in disabled state and from the Sub Job_Done the button will get either enabled or disabled based on a condition.

    I have used the following code, but I can't get it working. When I press the button, there is no difference in the Color of the Button in all the above said states. Can anyone one tell me what am I doing wrong ?

    Sub Activity_Create(FirstTime As Boolean)

    ' I need the button to be round
        Dim nRadius As Int
        nRadius = 
    DipToCurrent((BtnSave.Height + BtnSave.Width)/2)

    Dim EnabledClr,PressedClr,DisabledClr As ColorDrawable
    Colors.Blue, nRadius)
    Colors.Red, nRadius)
    Colors.Green, nRadius)

    'Create StateListDrawable
        Dim sld As StateListDrawable

        BtnSave.Background = sld

    'Here I expect the button to be displayed in the Disabled Color
        BtnSave.Enabled = False

    End Sub

    Sub BtnSave_Click
    Dim nResponse As Int
       nResponse = 
    Msgbox2("Shall I save this data ?","Confirmation required","Yes","","No",Null)
    If nResponse = DialogResponse.POSITIVE Then
    Msgbox("Not Saved","NOT OK")
    End If
    End Sub
    Initially I tried with the AppCompat ACFlatButton. As I could not get it working, I changed it to regular Button.

    Any help will be appreciated.

  2. Anser

    Anser Well-Known Member Licensed User

    FernandoGuedes likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice