基于焦点状态的自定义搜索栏和鞋子搜索栏拇指
customise seekbar and show seekbar thumb based on focussed state
我想按如下方式自定义我的搜索栏。并且还希望仅在搜索栏具有焦点时显示拇指,即当用户拖动搜索栏时。
您可以只在 onStopTrackingTouch()
中隐藏缩略图并使其在 onStartTrackingTouch()
中可见。
final SeekBar seekbar = findViewById(R.id.seekbar);
//Hide the seekbar's thumb.
seekbar.getThumb().setAlpha(0);
final Handler seekBarHandler = new Handler(Looper.getMainLooper());
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(final SeekBar seekbar, final int progress, final boolean feomUser)
{
//Do something...
}
public void onStartTrackingTouch(final SeekBar seekbar)
{
seekBarHandler.removeCallbacksAndMessages(null);
seekbar.getThumb().setAlpha(255);
}
public void onStopTrackingTouch(final SeekBar seekbar)
{
//Hide the thumb if not focus for a second.
seekBarHandler.postDelayed(new Runnable() {
public void run() {
seekbar.getThumb().setAlpha(0);
}
}, 1000L); //Delay
}
});
我想按如下方式自定义我的搜索栏。并且还希望仅在搜索栏具有焦点时显示拇指,即当用户拖动搜索栏时。
您可以只在 onStopTrackingTouch()
中隐藏缩略图并使其在 onStartTrackingTouch()
中可见。
final SeekBar seekbar = findViewById(R.id.seekbar);
//Hide the seekbar's thumb.
seekbar.getThumb().setAlpha(0);
final Handler seekBarHandler = new Handler(Looper.getMainLooper());
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(final SeekBar seekbar, final int progress, final boolean feomUser)
{
//Do something...
}
public void onStartTrackingTouch(final SeekBar seekbar)
{
seekBarHandler.removeCallbacksAndMessages(null);
seekbar.getThumb().setAlpha(255);
}
public void onStopTrackingTouch(final SeekBar seekbar)
{
//Hide the thumb if not focus for a second.
seekBarHandler.postDelayed(new Runnable() {
public void run() {
seekbar.getThumb().setAlpha(0);
}
}, 1000L); //Delay
}
});