-1
如何在webview android 3.1中選擇文本或突出顯示文本,同時單擊菜單?我已經實施,但它不起作用。任何人都可以告訴如何去做?如何在webview android3.1中選擇文本或突出顯示文本,同時點擊菜單按鈕
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case SELECTTEXT_MENU_ID:
//SelectText();
System.out.println("entering menu");
selectAndCopyText();
return true;
}
return true;
}
public void selectAndCopyText()
{
try
{
Method m = WebView.class.getMethod("emulateShiftHeld", null);
m.invoke(webview, null);
} catch (Exception e)
{
e.printStackTrace(); // fallback
KeyEvent shiftPressEvent = new KeyEvent(0,0, KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
shiftPressEvent.dispatch(webview);
}
}
感謝您的幫助