Android webview 不应该在长按时显示操作栏
Posted
技术标签:
【中文标题】Android webview 不应该在长按时显示操作栏【英文标题】:Android webview should not display action bar on long press 【发布时间】:2014-12-20 11:23:43 【问题描述】:当我在 android webview 中选择(长按)文本时,我不想完全显示操作栏,但我需要在屏幕上保持选择。我怎样才能做到这一点。提前致谢。
【问题讨论】:
【参考方案1】:使用 touch Listner 实现长按,然后在按钮 Preess[ACTION_DOWN] 上放置隐藏 ActionBar 的代码,并在按钮释放时放置显示操作栏的代码[ACTION_UP 或 ACTION_MOVE]
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;
很简单
【讨论】:
以上是关于Android webview 不应该在长按时显示操作栏的主要内容,如果未能解决你的问题,请参考以下文章
对于 iPhone - 但不是 iOS 模拟器 - UIToolbar UIBarButtonItem 将仅在长按时突出显示,而不是在点击时突出显示
Android - 从自定义列表视图中删除一个项目并在长按时更新它
如何使用选择器在长按时“永久”突出显示 ListView 行,但在正常按下时短暂显示