gpt4 book ai didi

javascript - 安卓 : Use javascript in textview

转载 作者:行者123 更新时间:2023-12-03 07:38:00 25 4
gpt4 key购买 nike

我有一个 View 分页器,每个页面都有一个 TextView ,我在我的 TextView 中解析了html文档(没有javascript),我在这个文档中有很多 anchor 标记,我想调用JavaScript函数在 anchor 标记中单击。例如

<a class="pginternal" tag="{http://www.w3.org/1999/xhtml}a" onclick="GoToPageNumber(186)" style="color:Blue !important;cursor:pointer !important;text-decoration:underline !important">THE VAMPIRE'S SIXTH STORY — In Which Three Men Dispute about a Woman.</a>

有“GoToPageNumber”事件,如何在点击时更改寻呼机项目位置

最佳答案

我已经找到解决方案了。将移动方法设置为textview。

textview.setMovementMethod(LinkMovementMethodExt.getInstance());

public static class LinkMovementMethodExt extends LinkMovementMethod
{
private static LinkMovementMethod sInstance;

public static MovementMethod getInstance()
{
if (sInstance == null)
{
sInstance = new LinkMovementMethodExt();
}
return sInstance;
}

int off = 0;
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event)
{
int action = event.getAction();

if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN)
{
try {
int x = (int) event.getX();
int y = (int) event.getY();

x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();

x += widget.getScrollX();
y += widget.getScrollY();

Layout layout = widget.getLayout();
int currentLine = layout.getLineForVertical(y);
int totalLine = layout.getLineCount();
off = layout.getOffsetForHorizontal(currentLine, x);
} catch (Exception e) {
e.printStackTrace();
}

try {
URLSpan[] urls = buffer.getSpans(off, off+1, URLSpan.class);
for(URLSpan span : urls)
{
String urlStr = span.getURL();

Log.v("URL SPAN", urlStr);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
}

关于javascript - 安卓 : Use javascript in textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35532853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com