[英]OnTouchListener webview always looping
i want to detect if i touch edit text type on my webview, i will show the floating action buttons.我想检测我是否在 webview 上触摸编辑文本类型,我将显示浮动操作按钮。 and if i touch unknown type the floating action buttons will be hide.如果我触摸未知类型,浮动操作按钮将被隐藏。
but here when i touch some position on my webview, it's looping between 4 / 5 times until i get the real touch type.但是在这里,当我触摸 web 视图上的某个位置时,它会在 4 / 5 次之间循环,直到我获得真正的触摸类型。
here is my code :这是我的代码:
@Override
public boolean onTouch(View v, MotionEvent event) {
WebView.HitTestResult hitTestResult = ((WebView) v).getHitTestResult();
if (hitTestResult.getType() == WebView.HitTestResult.EDIT_TEXT_TYPE) {
this.showKeyboard();
this.floatingActionButton.setVisibility(View.VISIBLE);
this.fabKeyboard.setVisibility(View.VISIBLE);
}else{
this.hideKeyboard();
this.floatingActionButton.setVisibility(View.GONE);
this.fabKeyboard.setVisibility(View.GONE);
}
Log.d("HIT RESULT", hitTestResult.getExtra() + " " + hitTestResult.getType());
return false;
}
here is my log :这是我的日志:
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
D/ViewRootImpl@c99fda4[MainActivity]: ViewPostIme pointer 1
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
// 9 IS Edit Text Type
D/HIT RESULT: null 9
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
// 0 Is Unknown Type
I think you need to use mWebview.requestFocus
and use Handler
process after listen event.我认为您需要使用mWebview.requestFocus
并在监听事件后使用Handler
进程。 Refer: https://developer.android.com/reference/android/webkit/WebView#requestFocus(int,%20android.graphics.Rect) and example: How to get link-URL in Android WebView with HitTestResult for a linked image (and not the image-URL) with Longclick请参阅: https : //developer.android.com/reference/android/webkit/WebView#requestFocus( int,%20android.graphics.Rect )和示例: How to get link-URL in Android WebView with HitTestResult for alinked image (而不是图像 URL)与 Longclick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.