【问题标题】:Tracking the selecting text in android webview跟踪android webview中的选择文本
【发布时间】:2011-12-14 10:53:32
【问题描述】:

在 android webview 中,我们可以选择网页中的文本。选择完成后,吐司将显示为“文本复制到剪贴板”。是否有可能避免那个吐司?我也想在选择文本后调用一个函数。我该怎么做?

帮帮我...

【问题讨论】:

    标签: android


    【解决方案1】:
    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);
          }     
       }
    };
    

    【讨论】:

    • 请在此处添加完整的 sn-p
    猜你喜欢
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 2012-05-16
    • 2011-10-20
    • 2016-07-05
    • 2010-11-09
    • 2019-04-18
    相关资源
    最近更新 更多