“Press and hold” button on Android needs to change states (custom XML selector) using onTouchListener

后端 未结 5 1402
北恋
北恋 2020-12-09 17:01

I\'ve got a button graphic which needs to have \"press and hold\" functionality, so instead of using onClickListener, I\'m using onTouchListener so that the app can react to

5条回答
  •  春和景丽
    2020-12-09 17:14

    Better solution:

    
    
        
            
        
        
            
        
    
    
    @Override
    public void onClick(View v) {
        if (v.isActivated())
           v.setActivated(false);
        else
           v.setActivated(true);
    }
    

提交回复
热议问题