单击按钮后如何保持按下状态? [英] How can I keep a button as pressed after clicking on it?

查看:209
本文介绍了单击按钮后如何保持按下状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Android.在该按钮创建的操作完成之前,如何保持按钮显示为按下"状态?

Possible Duplicate:
Android. How do I keep a button displayed as PRESSED until the action created by that button is finished?

我有一个按钮,当我按下按钮时希望它保持按下状态(Froyo上为绿色).

I have a button, and I want that when I press it, it stays as pressed (with the green color on Froyo).

有帮助吗?

mycodes_Button = (Button) findViewById(R.id.mycodes);
...
if (saved_Button.isPressed())
{
    saved_Button.setFocusable(true);
}

像这样吗?

推荐答案

使用以下代码.这很有用.

Use the following code. It's useful.

mycodes_Button.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        mycodes_Button.setPressed(true);
        return true;
    }
});

这篇关于单击按钮后如何保持按下状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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