Android系统。如何保持显示为preSSED一个按钮,直到由按钮创建的动作完成? [英] Android. How do I keep a button displayed as PRESSED until the action created by that button is finished?

查看:148
本文介绍了Android系统。如何保持显示为preSSED一个按钮,直到由按钮创建的动作完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 button_focused button_ pressed button_normal 图像。当我preSS的按钮,将显示 button_ pressed 形象和相关的按钮pressing的动作开始。

I have button_focused, button_pressed, and button_normal images. When I press the button, the button_pressed image is displayed and the action related to the button pressing begins.

当我退出pressing按钮,操作继续,但按钮返回 button_normal 图像显示。

When I quit pressing the button, the action continues but the button returns to button_normal image being displayed.

我怎样才能设置按钮图像在整个动作过程中显示为 button_ pressed ,然后重新设置为 button_normal 形象?

How can I set the button image being displayed to button_pressed during the entire action then reset to the button_normal image?

感谢您的时间

推荐答案

我用了一个像

void setHighlighted(boolean highlight) {
    button.setBackgroundResource( highlight
                                ? R.drawable.bbg_pressed
                                : R.drawable.button_background);
}

在这里button_background是选择定义 button_backgroung.xml

where button_background is a selector defined in button_backgroung.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
    <item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
    <item android:drawable="@drawable/bbg_normal"></item>
</selector>

也就是说,该code不与所使用的Andr​​oid框架的pressed国家干预;相反,它改变的背景下,这样的按钮看起来pressed。

That is, this code does not interfere with the pressed state used by the Android framework; instead, it changes the background so that the button looks pressed.

这篇关于Android系统。如何保持显示为preSSED一个按钮,直到由按钮创建的动作完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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