我正在尝试在webview上的片段中显示外部网站。虽然当我打开片段时,我得到一个空白屏幕。请帮助我。
public class one扩展了android.support.v4.app.Fragment {
public one() {
// Required empty public constructor
}
private WebView mWebview ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FrameLayout framelayout = (FrameLayout) inflater.inflate(R.layout.fragment_one, container, false);
mWebview = (WebView) framelayout.findViewById(R.id.web);
WebSettings setting =mWebview.getSettings();
mWebview.getSettings().setJavaScriptEnabled(true);
mWebview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
//webView.loadUrl("http://www.cleankutz.appointy.com");
mWebview.loadUrl("https://www.cleankutz.appointy.com");
return framelayout;
}
}
答案 0 :(得分:0)
清单中需要以下内容:
<manifest ... >
<uses-permission android:name="android.permission.INTERNET" />
...
</manifest>
以下是您可以尝试的一些事项:
启用java脚本:
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
另外,我觉得这段代码很无用:
mWebview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
这只会覆盖任何链接点击。如果你想这样做,你应该不设置Web视图客户端。此外,只是奖金,如果您希望您的webview重新按下,请执行以下操作:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
如果有帮助,请按复选标记接受我的回答。如果您有更多问题,请随时问我。