如何添加一个加载器对话框,我的WebView? [英] How can I add a loader dialog to my webview?
本文介绍了如何添加一个加载器对话框,我的WebView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图加载器对话框添加到我的WebView在我的应用程序。所以,你能帮我吗?
这是我的WebView的 code
公共类AlTibbiWebViewActivity延伸活动{
私人的WebView WV;
私人意图incomingIntent = NULL;
私人WebViewClient WVC =新WebViewClient(){
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
wv.loadUrl(URL);
返回true;
}
};
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.web_view);
this.wv =(web视图)findViewById(R.id.webView);
this.wv.setWebViewClient(WVC);
wv.getSettings()setJavaScriptEnabled(真)。
this.incomingIntent = getIntent();
串urlToLoad = incomingIntent.getExtras()的getString(urlToLoad);
//附标题MAP(删除Web视图头)
地图<字符串,字符串> AMAP =新的HashMap<字符串,字符串>();
aMap.put(应用程序,无);
// MYMAP = Collections.unmodifiableMap(AMAP);
wv.loadUrl(urlToLoad,AMAP);
}
解决方案
webView.setWebViewClient(新WebViewClient(){
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
view.loadUrl(URL);
返回true;
}
公共无效onLoadResource(web视图查看,字符串URL){
如果(progrDialog == NULL){
progrDialog =新ProgressDialog(YourActivity.this);
progrDialog.setMessage(载入中...);
progrDialog.show();
}
}
公共无效onPageFinished(web视图查看,字符串URL){
尝试{
如果(progrDialog.isShowing()){
progrDialog.dismiss();
progrDialog = NULL;
}
}赶上(例外的例外){
exception.printStackTrace();
}
}
});
I'm trying to add a loader dialog to my webview in my application. So, can you please help me with this?
This my webview code :
public class AlTibbiWebViewActivity extends Activity {
private WebView wv;
private Intent incomingIntent = null;
private WebViewClient wvc = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
wv.loadUrl(url);
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);
this.wv = (WebView) findViewById(R.id.webView);
this.wv.setWebViewClient(wvc);
wv.getSettings().setJavaScriptEnabled(true);
this.incomingIntent = getIntent();
String urlToLoad = incomingIntent.getExtras().getString("urlToLoad");
//EXTRA HEADER MAP (remove header from web view )
Map<String, String> aMap = new HashMap<String, String>() ;
aMap.put("app", "no");
//myMap = Collections.unmodifiableMap(aMap);
wv.loadUrl(urlToLoad , aMap);
}
解决方案
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource (WebView view, String url) {
if (progrDialog == null) {
progrDialog = new ProgressDialog(YourActivity.this);
progrDialog.setMessage("Loading...");
progrDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
try{
if (progrDialog.isShowing()) {
progrDialog.dismiss();
progrDialog = null;
}
}catch(Exception exception){
exception.printStackTrace();
}
}
});
这篇关于如何添加一个加载器对话框,我的WebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文