我正在创建一个带有 WebView 和页面顶部菜单的应用程序。我使该菜单不可见,并且仅在单击按钮时才会出现。这工作得很好,但那个按钮不能很好地适应任何地方,所以我没有点击一个按钮,所以当你双击屏幕时菜单会出现。所以这就是问题所在。双击仅适用于空白空间,但不适用于 WebView。我将如何让它工作,所以每当我双击屏幕时它就会出现/消失?
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;
}
}
任何帮助将不胜感激。