button的impressed()和onclickedlistener()的区别 我发现button里有一个方法叫impressed(),我测试了一下,当点击button时,都是调用的OnClickListener(),ispressed()并没有调用。那么这个方法是什么时候用的?我试过下面的代码: if(button.ispressed()){ system.out.print("button,ispressed"); } 发现并没有打印,请问前辈这个方法是怎么调用的? ------解决方案-------------------- 官方解释: Indicates whether the view is currently in pressed state. Unless setPressed(boolean) is explicitly called, only clickable views can enter the pressed state.
只有可点击的View才有Press状态
final Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) { if (btn.isPressed()) { System.out.println("pressed"); }