安卓:按钮状态改变事件 [英] Android: Button state changed event

查看:119
本文介绍了安卓:按钮状态改变事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按钮(如背景,文字颜色等),一些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.

这篇关于安卓:按钮状态改变事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆