2

我想从 editText 获取 HTML 标签。

将图像设置为 editText 代码如下。

String path = "images/sample.png";
Drawable drawable = Drawable.createFromStream(context.getAssets().open(path), null);
ImageGetter imageGetter = new ImageGetter() {
            @Override
            public Drawable getDrawable(String source) {
                drawable.setBounds(0, 0, mTextSize, mTextSize);
                return drawable;
            }
        };

        String img = "<img src=\"" + drawable.toString() + "\" />";

        Spanned spanned = Html.fromHtml(img, imageGetter, null);
        Log.i("HTML",spanned.toString());

        int start = this.getSelectionStart();
        int end = this.getSelectionEnd();

        this.getText().replace(Math.min(start, end), Math.max(start, end), spanned, 0, spanned.length());

如果我使用 editText.getText(),结果将被删除图像。

我想做以下事情:

String htmlTag = getHTML(); // I don't know this part.
myWebView.loadURL("javascript:setHTML(" + htmlTag + ")");

有人知道吗?

4

0 回答 0