我正在开发一个应用程序,该应用程序需要在 Button 经历不同状态(如禁用、突出显示等)时触发事件。我需要知道是否有人知道如何在按钮。
最佳答案
任何继承 View 的东西都有内置的状态,使用 setEnabled、setFocussed、setSelected、setPressed
如果您使用 StateList Drawable,则 drawable 将根据状态自动更改,它的内容如下(在 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>
然后您可以将它添加到按钮的 xml 布局中,所有这些都会自动管理。看 http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
关于android - 如何启用按钮状态android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6606315/