Android webview不应在长按时显示操作栏
我不想在android webview中选择长按文本时完全显示操作栏,但我需要在屏幕上保留选择。我怎样才能做到这一点。提前谢谢 使用touch Listner实现长按,然后将隐藏操作栏的代码放在按钮Preess[ACTION_DOWN]上,并将显示操作栏的代码放在按钮释放[ACTION_UP或ACTION_MOVE]上Android webview不应在长按时显示操作栏,android,android-actionbar,android-webview,long-press,Android,Android Actionbar,Android Webview,Long Press,我不想在android webview中选择长按文本时完全显示操作栏,但我需要在屏幕上保留选择。我怎样才能做到这一点。提前谢谢 使用touch Listner实现长按,然后将隐藏操作栏的代码放在按钮Preess[ACTION_DOWN]上,并将显示操作栏的代码放在按钮释放[ACTION_UP或ACTION_MOVE]上 ActionBar actionBar = getActionBar(); //on long presss hide ur action bar: textVi
ActionBar actionBar = getActionBar();
//on long presss hide ur action bar:
textView.setOnTouchListener(new OnTouchListener(){
private Timer longpressTimer; //won't depend on a motion event to fire
private final int longpressTimeDownBegin = 500; //0.5 s
private Point previousPoint;
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:{
longPressTimer = new Timer();
longpressTimer.schedule(new TimerTask(){
// hide the action bar
actionBar.hide();
}, longpressTimeDownBegin);
return true; //the parent was also handling long clicks
}
case MotionEvent.ACTION_MOVE:{
Point currentPoint = new Point((int)event.getX(), (int)event.getY());
if(previousPoint == null){
previousPoint = currentPoint;
}
int dx = Math.abs(currentPoint.x - previousPoint.x);
int dy = Math.abs(currentPoint.y - previousPoint.y);
int s = (int) Math.sqrt(dx*dx + dy*dy);
boolean isActuallyMoving = s >= minDisToMove; //we're moving
if(isActuallyMoving){ //only restart timer over if we're actually moving (threshold needed because everyone's finger shakes a little)
cancelLongPress();
return false; //didn't trigger long press (will be treated as scroll)
}
else{ //finger shaking a little, so continue to wait for possible long press
return true; //still waiting for potential long press
}
}
default:{
cancelLongPress();
// show the action bar
actionBar.show();
return false;
}
}
}
很简单