安卓:按钮状态改变事件
按钮(如背景,文字颜色等),一些XML属性可以用颜色或绘制状态列表像这样定义的:
Some XML attributes of buttons (such as background, textColor, etc) can be defined with color or drawable state List like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/>
<item android:state_focused="true"
android:color="#ff0000ff"/>
<item android:state_enabled="true"
android:color="#ff00ffff"/>
<item android:color="#ff000000"/>
</selector>
在视图状态更改(pressed / UN pressed为例),相应的颜色会自动改变。
When view state changes (pressed/unpressed, for example), corresponding color is changed automatically.
我怎么能prograqmmatically处理某种stateChangedEvent来执行更复杂的布局改变,不仅仅是改变颜色(例如,更改字体大小或设置其他文本)?
How can I prograqmmatically handle some kind of stateChangedEvent to perform more complicated layout change, than just changing a color (for example, change font size or set another text)?
有关焦点更改和触摸事件,你可以通过setOnFocusChangeListener和setOnTouchListener注册监听器。而关于禁用/启用状态的变化,你可以改变你的按钮状态后直接执行。
For focus changes and touch events you can register listeners by setOnFocusChangeListener and setOnTouchListener. And changes about disabled/enabled states you can perform directly after changing your button state.