Android: Programatically trigger text selection mode in a WebView on Jelly Bean

前端 未结 1 820
囚心锁ツ
囚心锁ツ 2021-01-05 13:55

I need to programatically trigger text selection mode in a WebView, but the code I have used does not work on Jelly Bean?

I have been using the following code but it

相关标签:
1条回答
  • 2021-01-05 14:24

    I have listed a potential solution in the comments here: How to enable the default highlight menus in android webview?

    Here is the content of the potential solution: After analyzing android.webkit.WebViewClassic I have had some success with the following:

    KeyEvent enterEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_ENTER,0,0);
    enterEvent.dispatch(this); 
    

    I thought more might be required as I needed to scroll down the WebView a little before the above worked when using an emulator, but after testing on a real JellyBean device the above seems to work fine.

    0 讨论(0)
提交回复
热议问题