本文整理了Java中android.webkit.WebView.dispatchKeyEvent()
方法的一些代码示例,展示了WebView.dispatchKeyEvent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.dispatchKeyEvent()
方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:dispatchKeyEvent
暂无
代码示例来源:origin: org.seleniumhq.selenium/selenium-android-driver
public void run() {
for (CharSequence sequence : text) {
for (int i = 0; i < sequence.length(); i++) {
char c = sequence.charAt(i);
int code = AndroidKeys.getKeyEventFromUnicodeKey(c);
if (code != -1) {
webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, code));
webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, code));
} else {
KeyEvent[] arr = characterMap.getEvents(new char[]{c});
if (arr != null) {
for (int j = 0; j < arr.length; j++) {
webview.dispatchKeyEvent(arr[j]);
}
}
}
}
}
done = true;
syncObject.notify();
}
});
代码示例来源:origin: stackoverflow.com
webview.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final WebView webview = (WebView) v;
final HitTestResult result = webview.getHitTestResult();
if(result.getType()==HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// 2. and here we get the url (remember to remove the WebView client and return true so that the hyperlink will not be really triggered)
mUrl = url; // mUrl is a member variant of the activity
view.setWebViewClient(null);
return true;
}
});
// 1. the picture must be focused, so we simulate a DPAD enter event to trigger the hyperlink
KeyEvent event1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
webview.dispatchKeyEvent(event1);
KeyEvent event2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER);
webview.dispatchKeyEvent(event2);
// 3. now you can do something with the anchor url (and then clear the mUrl for future usage)
String url = mUrl;
if (url!=null) {
Toast.makeText(webview.getContext(), url, Toast.LENGTH_SHORT).show();
}
mUrl = null;
}
return false;
}
});
内容来源于网络,如有侵权,请联系作者删除!