我有一个自定义的WebView,当我得到一个MotionEvent.ACTION_DOWN时,我想模拟一下点击。我不想在WebView上有任何类型的输入,我甚至不能让它可点击(.setClickable(False))。因此,我所做的就是覆盖自定义WebView中的onTouchEvent()以返回false。
这工作得很好,但我错过了点击。我在WebView的源代码中看到,它向名为WebViewCore的类发送消息,但这种通信在每个版本的安卓中都是不同的。
有人知道如何以编程方式将单击发送到webView吗?
这是我想要做的:
public class VoidWebView extends WebView {
public VoidWebView(Context context) {
super(context);
}
public VoidWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
//tell the webview that a click has been performed , it doesn't matter where the click happened
}
return false;
}
}发布于 2012-11-29 00:13:20
我认为您正在寻找View的performClick()方法。
你可以在here上获得更多信息。
发布于 2012-11-29 00:15:07
将事件向上和向下传递给超类。
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP){
super.onTouchEvent(event);
return true;
}
return false;
}https://stackoverflow.com/questions/13609035
复制相似问题