user788511
user788511

Reputation: 1736

how to enable button states android

I am working on an application that requires events to be fired off when the Button experiences different states like Disabled, Highlighted etc. I need to know if anyone knows how I can define these states on a Button.

Upvotes: 1

Views: 2476

Answers (3)

Marmoy
Marmoy

Reputation: 8079

There are these methods available for Button: isEnabled(), isFocused(), isPressed() and more.

Try taking a look at http://developer.android.com/reference/android/view/View.html#pubmethods since Button inherits these methods from View.

Upvotes: 0

Sumit
Sumit

Reputation: 746

Along with the link provided by "siliconeagle" also check this link.... http://developer.android.com/reference/android/widget/Button.html

This contains the description about the methods available in Views such as onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) etc.

Upvotes: 1

siliconeagle
siliconeagle

Reputation: 7383

Anything subclassing View has the states built in, use setEnabled, setFocussed, setSelected, setPressed

if you use a StateList Drawable the drawables will automatically be changed dependingon the state, it goes in something like this (in res/drawable/buttonexample.xml):

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/butt_add_on_32" />
    <item android:drawable="@drawable/butt_add_off_32" />
</selector>

then you can add it in you xml layout for the button and it all get managed automatically. see http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Upvotes: 2

Related Questions