上一篇博客提到WebView封装了很多功能,大大方便了开发者的使用。
WebView提供了一个loadUrl();参数就是字符串参数,就是你要进入的网址的字符串。
一下简单的代码就实现了简单的网页浏览功能。
private EditText url ;
private Button go;
private WebView show;
url = (EditText)findViewById(R.id.url);
show = (WebView)findViewById(R.id.show);
//这一行 com.example.onclickListener这个是一个包名来的,因为我把响应时间都放在一个包里面进行管理,方便以后维护
go.setOnClickListener(new com.example.onclickListener.Go(this,url,show));
public class Go implements OnClickListener {
Context context;
EditText url;
WebView show;
public Go(Context context,EditText url,WebView show) {
this.context = context;
this.url = url;
this.show = show;
}
public void onClick(View v) {
String urlStr =url.getText().toString();
show.loadUrl(urlStr);
}
}