问题描述
我开发一个应用程序,有一个片段,显示网站的web视图。对于慢速连接它需要时间来加载网页和应用程序获取,所以我想告诉我的片段的全屏加载微调空白几秒钟。我发现源$ C $ C,但我不知道如何在我的课扩展片段实现这一点。
I am developing an app that has a fragment to show website on the webview. For slow connection it takes times to load the website and the app gets blank for few seconds so I want to show a full screen loading spinner in my fragment. I have found source code but I don't know how to implement this in my class that extends fragment.
这是我的片段,我想展示的网站之前,以显示全屏加载。
This is my fragment where I want to show the full screen loading before showing the website.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.fragment_a, container, false);
String url="http://www.hotelsearcher.net/";
Bundle args = getArguments();
if (args != null){
url = args.getString("position");
}
WebView webView= (WebView) V.findViewById(R.id.webView1);
WebSettings webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setPluginState(PluginState.ON);
webView.setWebViewClient(new WebViewClient());
adview =(AdView) V.findViewById(R.id.ads);
Ads.loadAds(adview);
webView.loadUrl(url);
return V;
}
}
我发现这是code: https://gist.github.com/ daichan4649 / 5344979 /下载#
谁能告诉我,我应该怎么写。要实现该功能。
Can anybody tell me what should I write. to implement the feature.
推荐答案
在你的 onCreateView()
您需要出示进度
,因为你的 webView.loadUrl(URL)
需要时间来加载你的的WebView
的互联网内容。所以,你需要注册一个回调,当你的的WebView
加载完成您的内容。你可以听这样的:
In your onCreateView()
you need to show a ProgressBar
, since your webView.loadUrl(url)
takes time to load the internet content on your WebView
. So you need to register for a call back when your WebView
is done loading your content. You can listen like this :
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// Cancel your ProgressBar here
}
});
在你的 onPageFinished()
取消进度
因为你的的WebView
已完成加载的内容。
Inside your onPageFinished()
cancel your ProgressBar
since your WebView
has completed loading the content.
工作code
public class MainActivity extends Activity {
private String url = "https://www.google.co.in/";
ProgressDialog pb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = new ProgressDialog(this);
pb.setTitle("Connecting Station");
pb.setMessage("Please Wait....");
pb.setCancelable(false);
pb.show();
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setPluginState(PluginState.ON);
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
pb.dismiss();
}
});
}
}
这篇关于如何全屏显示加载微调的的WebView在Android的碎片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!