判断webview有没有上一页
2个回答
展开全部
android中含有一webview,并成功载入所指的url的页面了,主程序代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1xml);
handler=new Handler()
{
public void handleMessage(android.os.Message msg) {
if(Thread.currentThread().isInterrupted()){
switch(msg.what){
case 0:
pd.show();
break;
case 1:
pd.hide();
break;
}
}
};
};
init();
loadUrl(wv, "ht tp:/ /n c.8 ff.c n/m.ph p");
});
}
public void init(){
wv=(WebView) findViewById(R.id.webview1);
//可用js
wv.getSettings().setJavaScriptEnabled(true);
//滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上
wv.setScrollBarStyle(0);
wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
loadUrl(view, url);
return super.shouldOverrideUrlLoading(view, url);
}
});
wv.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
if(newProgress==100){
handler.sendEmptyMessage(1);
}
super.onProgressChanged(view, newProgress);
}
});
pd=new ProgressDialog(Tab1Activity.this);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage("数据加载中,请稍候...");
}
public void loadUrl(final WebView webView,final String url){
new Thread(){
@Override
public void run() {
handler.sendEmptyMessage(0);
webView.loadUrl(url);
}
}.start();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1xml);
handler=new Handler()
{
public void handleMessage(android.os.Message msg) {
if(Thread.currentThread().isInterrupted()){
switch(msg.what){
case 0:
pd.show();
break;
case 1:
pd.hide();
break;
}
}
};
};
init();
loadUrl(wv, "ht tp:/ /n c.8 ff.c n/m.ph p");
});
}
public void init(){
wv=(WebView) findViewById(R.id.webview1);
//可用js
wv.getSettings().setJavaScriptEnabled(true);
//滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上
wv.setScrollBarStyle(0);
wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
loadUrl(view, url);
return super.shouldOverrideUrlLoading(view, url);
}
});
wv.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
if(newProgress==100){
handler.sendEmptyMessage(1);
}
super.onProgressChanged(view, newProgress);
}
});
pd=new ProgressDialog(Tab1Activity.this);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage("数据加载中,请稍候...");
}
public void loadUrl(final WebView webView,final String url){
new Thread(){
@Override
public void run() {
handler.sendEmptyMessage(0);
webView.loadUrl(url);
}
}.start();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mWebView.canGoBack()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询