gpt4 book ai didi

android - 点击监听器上的搜索栏拇指

转载 作者:太空狗 更新时间:2023-10-29 14:58:30 28 4
gpt4 key购买 nike

我想在搜索栏的拇指上注册一个可点击事件,以便在用户点击它时打开 Activity 。是否可以?我在这里发现了类似的问题 Seekbar's thumb on click但没有找到答案。我不想移动搜索栏,但想在用户仅点击搜索栏的重击时打开 Activity 。

最佳答案

这将在用户点击拇指时触发。请参阅 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
}

});

关于android - 点击监听器上的搜索栏拇指,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29209241/

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