0
在常規瀏覽器中,長按鏈接會顯示上下文菜單。我明白爲什麼這不會發生在WebView中,並且我沒有出現內容菜單。然而,我想要發生的事情是,長按觸發鏈接,就好像正常鏈接一樣。目前,長期緊張的聯繫根本沒有做任何事情。我能做些什麼來使長時間的鏈接像正常一樣觸發它們?如何使WebView中的長按鏈接觸發鏈接與正常一樣?
我的代碼:
package com.example.testing;
import java.util.UUID;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
private WebView mWebView;
private ProgressBar mProgressBar;
private ImageView mSplashScreen;
@SuppressLint("SetJavaScriptEnabled") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
mSplashScreen = (ImageView) findViewById(R.id.splashscreen);
mSplashScreen.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.VISIBLE);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
mProgressBar.setProgress(progress);
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
mWebView.loadUrl("file:///android_asset/error.html");
}
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
mProgressBar.setProgress(0);
mProgressBar.setVisibility(View.VISIBLE);
webview.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
mWebView.setVisibility(View.VISIBLE);
mSplashScreen.setVisibility(View.GONE);
mProgressBar.setVisibility(View.GONE);
}
});
mWebView.loadUrl("http://example.com/");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mProgressBar.setProgress(0);
mProgressBar.setVisibility(View.VISIBLE);
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}