android.webkit.WebView.dispatchKeyEvent()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中android.webkit.WebView.dispatchKeyEvent()方法的一些代码示例,展示了WebView.dispatchKeyEvent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.dispatchKeyEvent()方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:dispatchKeyEvent

WebView.dispatchKeyEvent介绍

暂无

代码示例

代码示例来源:origin: org.seleniumhq.selenium/selenium-android-driver

  1. public void run() {
  2. for (CharSequence sequence : text) {
  3. for (int i = 0; i < sequence.length(); i++) {
  4. char c = sequence.charAt(i);
  5. int code = AndroidKeys.getKeyEventFromUnicodeKey(c);
  6. if (code != -1) {
  7. webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, code));
  8. webview.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, code));
  9. } else {
  10. KeyEvent[] arr = characterMap.getEvents(new char[]{c});
  11. if (arr != null) {
  12. for (int j = 0; j < arr.length; j++) {
  13. webview.dispatchKeyEvent(arr[j]);
  14. }
  15. }
  16. }
  17. }
  18. }
  19. done = true;
  20. syncObject.notify();
  21. }
  22. });

代码示例来源:origin: stackoverflow.com

  1. webview.setOnLongClickListener(new OnLongClickListener() {
  2. @Override
  3. public boolean onLongClick(View v) {
  4. final WebView webview = (WebView) v;
  5. final HitTestResult result = webview.getHitTestResult();
  6. if(result.getType()==HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
  7. webview.setWebViewClient(new WebViewClient(){
  8. @Override
  9. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  10. // 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)
  11. mUrl = url; // mUrl is a member variant of the activity
  12. view.setWebViewClient(null);
  13. return true;
  14. }
  15. });
  16. // 1. the picture must be focused, so we simulate a DPAD enter event to trigger the hyperlink
  17. KeyEvent event1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
  18. webview.dispatchKeyEvent(event1);
  19. KeyEvent event2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER);
  20. webview.dispatchKeyEvent(event2);
  21. // 3. now you can do something with the anchor url (and then clear the mUrl for future usage)
  22. String url = mUrl;
  23. if (url!=null) {
  24. Toast.makeText(webview.getContext(), url, Toast.LENGTH_SHORT).show();
  25. }
  26. mUrl = null;
  27. }
  28. return false;
  29. }
  30. });

相关文章

WebView类方法