在android中使用progressbar的webview
我添加了在android中使用progressbar的webview,android,webview,Android,Webview,我添加了MainActivity.java和webclient.java的代码。网站加载到WebView,但WebView的进度不会显示在ProgressBar中。请帮帮我 对我来说已经足够了。 如果您对android中的Web服务有所了解,请给出一些想法。那肯定对我有帮助。谢谢。尝试在onCreate()中添加此行 this.getWindow().setFeatureInt(Window.FEATURE\u进度,Window.PROGRESS\u可见性\u打开) 这将使进度可见this.ge
MainActivity.java
和webclient.java
的代码。网站加载到WebView
,但WebView的进度不会显示在ProgressBar
中。请帮帮我
对我来说已经足够了。
如果您对android中的Web服务有所了解,请给出一些想法。那肯定对我有帮助。谢谢。尝试在onCreate()中添加此行
this.getWindow().setFeatureInt(Window.FEATURE\u进度,Window.PROGRESS\u可见性\u打开)代码>
这将使进度可见this.getWindow().setFeatureInt(Window.FEATURE\u progress,Window.progress\u VISIBILITY\u ON)代码>
这将使进度在操作栏上可见
*
> MainActivity.java
*
package com.example.net_progress;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import com.example.net_progress.*;
public class MainActivity extends Activity implements OnClickListener {
public MainActivity() {
//pb.setProgress(progress);
}
WebView wv;
ProgressBar pb;
Button go;
String url;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb=(ProgressBar)findViewById(R.id.progressBar1);
et=(EditText)findViewById(R.id.editText1);
go=(Button)findViewById(R.id.button1);
go.setOnClickListener(this);
wv=(WebView)findViewById(R.id.webView1);
wv.setWebChromeClient(Myclient());
pb.setMax(100);
}
private WebChromeClient Myclient() {
// TODO Auto-generated method stub
return null;
}
public void setValue(int progress) {
pb.setProgress(progress);
}
boolean validateUrl(String url)
{
return true;
}
@Override
public void onClick(View v) {
if(v.getId()==R.id.button1)
{
url=et.getText().toString();
if(validateUrl(url))
{
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://"+url);
pb.setProgress(0);
}
}
}
}
package com.example.net_progress;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
public class Myclient extends WebChromeClient {
public void onProgressChanged(WebView wv, int newProgress) {
MainActivity mn=new MainActivity();
mn.setValue(newProgress);
super.onProgressChanged(wv, newProgress);
}
}