【发布时间】:2017-10-04 11:51:42
【问题描述】:
我对 web 视图中的超链接有疑问。我浏览了所有解决类似问题的链接,但没有找到任何解决相同问题的链接。
我有一个自定义 Web 视图,它对特定手势执行一些操作。我想这是禁用超链接的触摸。
如何保持手势并启用超链接并调用 shouldOverrideUrlLoading?
这是我拥有的自定义网页视图:
public class newBTWebView extends WebView implements QuickAction.OnDismissListener, PopoverView.PopoverViewDelegate, GestureDetector.OnGestureListener {
public newBTWebView(Context context) {
super(context);
this.ctx = context;
setup(context);
init(context);
}
public newBTWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.ctx = context;
setup(context);
init(context);
}
public void init(Context context) {
this.context = context;
setInitialScale(100);
this.getSettings().setJavaScriptEnabled(true);
Configuration conf = getResources().getConfiguration();
int screenLayout = 1;
try
{
Field field = conf.getClass().getDeclaredField("screenLayout");
screenLayout = field.getInt(conf);
}
catch (Exception e) {
}
loadingNewChap = false;
screenType = screenLayout & 15;
gestureScanner = new GestureDetector(this);
this.setVerticalScrollBarEnabled(false);
this.setHorizontalScrollBarEnabled(false);
this.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
countDown++;
}
if(event.getAction() == MotionEvent.ACTION_UP && isLongPress)
{
//do selection
}
return gestureScanner.onTouchEvent(event);
}
});
}
我还实现了手势的功能:onFlingDo、onSingleTapUp、onShowPress、onLongPress、onDown
这就是我在活动中调用 webview 的方式:
testWV = (newBTWebView) findViewById(R.id.mywebview1);
testWV.setVerticalScrollBarEnabled(false);
testWV.setHorizontalScrollBarEnabled(false);
testWV.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
super.shouldOverrideUrlLoading(view, url);
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
@Override
public void onPageFinished(WebView view, String url) {
}
}
我怎样才能保持手势并仍然捕获超链接点击?
【问题讨论】:
-
亲爱的投票者,请在投票中说明其背后的原因,以便我修复它。谢谢。
-
既然你问:反对票可能是因为不必要的编辑战。应始终保留好的编辑,除非它们改变了帖子的含义。
标签: android webview hyperlink gesture