gpt4 book ai didi

android - 使双击在 WebView 中起作用

转载 作者:行者123 更新时间:2023-11-29 22:07:40 27 4
gpt4 key购买 nike

我有一个具有某些双击功能的网站,因此当您在浏览器中双击时,对于 android,它只会缩放。所以我正在构建一个 WebView,这样我就可以超越双击并让它做出应有的 react 。

public class myWebView extends Activity{

GestureDetector gs = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView engine = (WebView) findViewById(R.id.web_engine);
engine.getSettings().setJavaScriptEnabled(true);
engine.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
engine.getSettings().setSupportMultipleWindows(true);
engine.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
engine.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});

engine.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gs == null) {
gs = new GestureDetector(
new GestureDetector.SimpleOnGestureListener() {
//overrides the double click
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// SOME CODE THAT SIMULATES A DOUBLE CLICK
return true;
}
});
}
gs.onTouchEvent(event);
return false;
}
});
engine.loadUrl("http://www.google.com");
}
}

所以函数 onDoubleTapEvent(MotionEvent e) 将在双击事件中执行两者之间的任何操作。 The above code is mostly thanks too Cehm .

所以此时我需要欺骗它执行双击。我可以在那里模拟几次点击吗?

最佳答案

尝试一次:

private GestureDetector gs = null;

private OnTouchListener onTouch = new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {

if (gs == null) {
gs = new GestureDetector(
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTapEvent(MotionEvent e) {

//Double Tap
snapWebView.zoomIn();//Zoom in
return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {

//Single Tab
snapWebView.zoomOut();// Zoom out
return false;
};
});
}

gs.onTouchEvent(event);

return false;
}
};

最后,将OnTouch事件设置为WebView:

webView.setOnTouchListener(onTouch);

查看详情:How to make Double Click in WebView?

关于android - 使双击在 WebView 中起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10418757/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com