1
package com.example.notesexample;

import android.os.Bundle;
import android.app.Activity;

import android.webkit.WebView;

public class MainActivity extends Activity {

    WebView web;
    String str2 = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework"
            + "help help with homework homework assignments elementary school high school middle school"
            + "// --><font color='#60c000' size='4'><strong>Please!</strong></font>"
            + "<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif'  />";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        web = (WebView) findViewById(R.id.webView1);
        web.loadDataWithBaseURL("", str2, "text/html", "UTF-8", "");

    }

}

这是我的代码我现在在 web 视图中显示一些文本我想要什么我想要在触摸选择上复制文本我有一个单词和一个段落我需要在 android webview 文本中复制就像这个示例 [ https://support.mozilla。 org/en-US/kb/how-do-i-copy-and-paste-text-android ] 请帮助我如何做到这一点。谢谢我是这个android功能的新手。

4

1 回答 1

2

从扩展 WebView 的类:

public void selectAndCopyText() {
try {
    Method m = WebView.class.getMethod("emulateShiftHeld", null);
    m.invoke(this, null);
} catch (Exception e) {
    e.printStackTrace();
    // fallback
    KeyEvent shiftPressEvent = new KeyEvent(0,0,
         KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
    shiftPressEvent.dispatch(this);
}

}

然后你必须使用 ClipboardManager 来观察新文本。

于 2013-09-24T11:55:01.950 回答