2011-12-14 60 views
6

在android webview中,我們可以選擇網頁中的文本。選擇完成後,Toast將顯示爲「文本複製到剪貼板」。是否有可能避免烤麪包?另外我想在選擇文本後調用一個函數。我怎樣才能做到這一點?跟蹤android webview中的選擇文本

幫我...

回答

5
public boolean onTouch(View v, MotionEvent event) { 
    if (event.getAction() == android.view.MotionEvent.ACTION_UP) {    
     // when user finished selection this loop will execute to get 
     // selected text in webview. 
     if(mark_text == true) 
     {      
      mark_text = false; 
      clipboardManager.setText("XXXXXX");  
      webView.postDelayed(onClipBoard, 1000); 
     } 
    } 
} 


private Runnable onClipBoard=new Runnable() { 
    public void run() {     
      // if selected text is copied in clipboard toast will show the 
      // correct text otherwise else part will execute     
     if (!clipboardManager.getText().toString().equalsIgnoreCase("XXXXXX")) { 
      Toast.makeText(getApplicationContext(), 
        "selected Text = " + clipboardManager.getText().toString(), 
        Toast.LENGTH_LONG).show(); 
      clipboardManager.setText("XXXXXX"); 

     } else { 
      webView.postDelayed(onClipBoard, 1000); 
     }  
    } 
}; 
+1

請在此處添加完整的片段 – 2016-08-28 16:53:52