这个问题已经在这里有了答案:




已关闭8年。






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

有什么帮助吗?

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

像这样吗?

最佳答案

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

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

关于android - 单击按钮后如何保持按下状态? [复制],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4747311/

10-09 06:53
查看更多