在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/