Prasanth
Prasanth

Reputation: 507

Text Selection In Android Webview

to select text in web view below code is working fine

KeyEvent shiftPressEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0)                       
shiftPressEvent.dispatch(webView);

but that dispatch method is deprecated. so instead of that i like to use this

 public final boolean dispatch (KeyEvent.Callback receiver, KeyEvent.DispatcherState state, Object target) 

give me an idea from the above function to select text.

Upvotes: 1

Views: 1290

Answers (1)

codeetcetera
codeetcetera

Reputation: 3203

I got web view selections working in 2.2 - 4.0.3 using a javascript interface that gets all touches passed to it. The solution seems to work pretty well and I've put an example project on github. The github project includes the necessary js in the assets folder as well as a test page and web view that loads the test page and implements all necessary methods to handle the selection. The link to the github project is https://github.com/btate/BTAndroidWebViewSelection. Have at it.

Upvotes: 3

Related Questions