Android的 - 双击的WebView检测 [英] Android - Double tap WebView detect
问题描述
我创建一个web视图的应用程序,并在页面顶部的菜单。我提出,菜单是不可见的,并且单击按钮时会才会出现。这工作不错,但该按钮可能不适合在任何地方这么好听,而不是点击一个按钮,我做到了,这样的菜单会出现,当你双击屏幕上。
因此,这里的问题。双击只适用于空,但不是的WebView。我将如何使它工作,所以它会出现/消失,每当我双击屏幕?
I am creating an app with a WebView and a menu on top of the page. I made that menu is invisible and would only appear when a button is clicked. That worked fine but that button couldn't fit anywhere nicely so instead of clicking a button I made it so that the menu would appear when you double tap on the screen. So here's the problem. Double tap only works on empty space, but not on WebView. How would I make it work, so it would appear/disappear whenever I double tap the screen?
public class MainActivity extends Activity implements OnGestureListener{
private WebView webView;
LinearLayout toolbar;
private GestureDetector gd;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
webView =((WebView)findViewById(R.id.webView1));
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setVerticalScrollBarEnabled(true);
webView.loadUrl("URL_HERE");
gd = new GestureDetector(this);
gd.setOnDoubleTapListener(new OnDoubleTapListener()
{
@Override
public boolean onDoubleTap(MotionEvent e)
{
LinearLayout toolbar= (LinearLayout)findViewById(R.id.toolbar);
if(toolbar.getVisibility() == View.GONE){
toolbar.setVisibility(View.VISIBLE);
}
else {
toolbar.setVisibility(View.GONE);
}
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e)
{
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e)
{
return false;
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
return gd.onTouchEvent(event);//return the double tap events
}
@Override
public boolean onDown(MotionEvent e)
{
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
return false;
}
@Override
public void onLongPress(MotionEvent e)
{
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
return false;
}
@Override
public void onShowPress(MotionEvent e)
{
}
@Override
public boolean onSingleTapUp(MotionEvent e)
{
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
任何帮助将AP preciated。
Any help will be appreciated.
推荐答案
你有没有尝试添加此?
webView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gd.onTouchEvent(event);
}
});
这篇关于Android的 - 双击的WebView检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!