开发者

how to enable button states android

I am working on an app开发者_Go百科lication 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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜