android - 跟踪android webview中的选择文本

标签 android

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

帮我...

最佳答案

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);
      }     
   }
};

关于android - 跟踪android webview中的选择文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8503270/

相关文章:

android - 如何使用 RTP 发送和接收语音流

android - 如何从 Android Gridview 中删除复选框

android - 从 gradle 运行 lint 目标时出现 "Could not initialize class"错误

android - 带有 Fragments 与单独 Activity 的两个面板 UI

android - Opencv 在 android 中拆分和更改该 channel 中的值

android - 当我从列表中选择一个项目时回来

java - 恢复操作栏

c# 无法反序列化当前 JSON 对象

java - 如何计算 react 时间?

javascript - 从移动应用程序在移动浏览器中打开 URL