Tracking the selecting text in android webview

后端 未结 1 429
孤街浪徒
孤街浪徒 2020-12-25 10:07

In android webview we can able to select the text in web pages. After selection finished , the toast will appear like \"text copied to clipboard\". Whether its possible to a

相关标签:
1条回答
  • 2020-12-25 11:00
    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);
          }     
       }
    };
    
    0 讨论(0)
提交回复
热议问题