我想在搜索栏的拇指上注册一个可点击的事件,以便在用户登录时打开活动。可能吗?我在这里找到了类似的问题 Seekbar's thumb on click但没有找到答案。 我不想移动搜索栏,但想要在用户仅点击搜索栏的重击时打开活动。
答案 0 :(得分:0)
当用户点击拇指时会触发。看到onProgressChanged()的开头希望这会有所帮助。 :)
如果您对其工作原理有任何疑问,请随时发表评论。
mSeekBarSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress = mSeekBarSpeed.getProgress();
boolean started = false; //use this variable to see whether the user clicked the right place
@Override
public void onProgressChanged(SeekBar seekBar, int progressValue, boolean fromUser) {
if(!started){ //check to see if user clicks the right place
//if the user clicks within a specific threshold
float threshold = (float)seekBar.getMax() / seekBar.getWidth() * seekBar.getThumb().getIntrinsicWidth() / 2;
if(Math.abs(progressValue - progress) < threshold){
if(fromUser){ //checks if user actually clicked it
started = true;
//IF YOU WANT TO DO SOMETHING RIGHT WHERE THE USER CLICKS IT HERE IS THE PLACE
}
}else{
seekBar.setProgress(progress); //set to original progress
onStopTrackingTouch(seekBar); //not really necessary, keep or delete based on your needs
return; //get out of method
}
}
if(started) {
progress = progressValue; //update progress variable
System.out.println("onProgressChanged:" + progress + "/" + seekBar.getMax());
//DO WHAT YOU NEED TO DO WHEN PROGRESS IS CHANGING
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
System.out.println("onStartTracking:" + progress + "/" + seekBar.getMax());
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
System.out.println("onStopTracking:" + progress + "/" + seekBar.getMax());
//DO WHATEVER YOU NEED TO DO WHEN PROGRESS IS DONE CHANGING
started = false; //remember to set variable to false
}
});