gpt4 book ai didi

java - setPressed 不起作用

转载 作者:行者123 更新时间:2023-12-01 21:25:47 25 4
gpt4 key购买 nike

我的代码中有这个,但 .setPressed 不起作用:

Button btndesligado = (Button) findViewById(R.id.button12);
btndesligado.setOnClickListener(new OnClickListener() { //Botão para pôr silêncio!

@Override
public void onClick(View v) {

btndesligado.setPressed(true);
som = false;
vibrar = false;

}
});

出了什么问题?它不会给我任何错误,只是当我打开它并单击它时它不起作用。本来按一次就按了。

最佳答案

Android 会在 onClickEvent 之前和之后更改 setPressed

所以改变你的代码这个代码

btndesligado.setOnClickListener(new OnClickListener() { //Botão para pôr silêncio!

@Override
public void onClick(View v) {

btndesligado.setPressed(true);
som = false;
vibrar = false;

}
});

到此

 btndesligado.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {

// show interest in events resulting from ACTION_DOWN
if (event.getAction() == MotionEvent.ACTION_DOWN) return true;

// don't handle event unless its ACTION_UP so "doSomething()" only runs once.
if (event.getAction() != MotionEvent.ACTION_UP) return false;


btndesligado.setPressed(true);
som = false;
vibrar = false;
return true;
}
});

关于java - setPressed 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com