我现在非常坚持以下问题。 我得到了这个我无法访问的HTML代码(Snippet):
<div class="story_pic"
style="backgroundimage:url('http://#####.jpg');"
data-origpic="http://#####.jpg">
</div>
现在我想在我的Android WebView上禁用这些图片上的点击可能性。
我尝试过的事情: 1)OnTouchListener
mWebView.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
WebView.HitTestResult hr = ((WebView) v).getHitTestResult();
Log.i(TAG, "getExtra = " + hr.getExtra() + "\t\t Type=" + hr.getType());
return false;
}
});
创建:getExtra = null Type = 0
2.)WebViewClient:
private class SampleWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.d(TAG, "#url: " + url);
}
}
创建:没有
提前致谢!
答案 0 :(得分:0)
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
使用android:clickable =&#34; false&#34;不会禁用触摸事件。
创建自定义WebViewClient
并覆盖shouldOverrideUrlLoading
&amp; shouldOverrideKeyEvent
。例如:
public class MyWebViewClient extends WebViewClient {
public boolean shuldOverrideKeyEvent (WebView view, KeyEvent event) {
// Do something with the event here
return true;
}
public boolean shouldOverrideUrlLoading (WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.google.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// reject anything other
return true;
}
}