我在Android中的Webview中遇到了Setdata问题 问题是我无法在Webview中设置特定的URL 例如,我可以设置http://www.youtube.com,但我无法设置 http://www.youtube.com/user/androiddevelopers我不知道该做什么以及为什么 它无法正常工作
public class FragmentA extends Fragment {
public FragmentA() {
Log.i("in :","on cons");
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View mainView = inflater.inflate(R.layout.first_fragment, container, false);
WebView wv = (WebView)mainView.findViewById(R.id.url);
wv.setWebViewClient(new MyWebViewClient());
wv.getSettings().setPluginState(WebSettings.PluginState.ON);
wv.getSettings().setBuiltInZoomControls(false);
wv.getSettings().setSupportZoom(false);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setDomStorageEnabled(true);
wv.loadUrl("here is my problem");
return mainView;
}
public class MyWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("here is where i will put the url to check") == true) {
view.loadUrl(url);
}
else
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
return true;
}
}
}
答案 0 :(得分:0)
这可能会解决您的问题。
webView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});