简单的页面跳转

package com.example.webtest;
import java.security.PublicKey;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private String url = "http://2014.qq.com/";
private ProgressDialog progressDialog;
private WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
web = (WebView) findViewById(R.id.web);
// Uri uri = Uri.parse(url);
// URL:统一资源定位符 也就是网址 例如 http://www.microsoft.com/
// URI:通用资源标志符 http://www.acme.com/support/suppliers.htm
// Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// startActivity(intent);
init();
/*
* Uri uri = Uri.parse(url); // url为你要的链接 Intent intent = new
* Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
*/
}
private void init() {
// TODO Auto-generated method stub
// Log.d("tag", "DAYIN");
web.loadUrl(url);
// web.loadUrl("file:///android_asset/1.html");
web.setWebViewClient(new WebViewClient() {
// 覆盖webView默认通过第三方或者是系统浏览器打开网页的行为,使得网页可以在WebView中打开
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
// 返回值是TRUE的时候控制网页在webview中打开,如果为false的时候则调用系统浏览器或者第三方浏览器打开
return super.shouldOverrideUrlLoading(view, url);
}
});
// Webviewclient帮助webview去处理一些页面控制和请求通知。
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);// 使得手机自动适应网页
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); // webvie加载页面优先使用缓存加载
web.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
// TODO Auto-generated method stub
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
// 网页加载完毕, 关闭progressDialog
closeDialog();
} else {
openDialog(newProgress);
}
}
private void openDialog(int newProgress) {
// TODO Auto-generated method stub
if (progressDialog == null) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle("正在加载中");
progressDialog
.setProgressStyle(progressDialog.STYLE_HORIZONTAL);
progressDialog.setProgress(newProgress);
progressDialog.show();
} else {
progressDialog.setProgress(newProgress);// 显示新的进度
}
}
private void closeDialog() {
// TODO Auto-generated method stub
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();// 取消显示
progressDialog = null;
}
}
});
 
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// 改写物理按键--返回的逻辑
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (web.canGoBack()) {
web.goBack();
return true;// 在javaScript里,return有终止函数的执行和传递数值,两种功能。
// return false 就是返回假值,从而终止了函数的执行
// return true 就是返回真值,从而传递数值,继续执行函数
} else {
System.exit(0);
}
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

web.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent"/> </LinearLayout>

使用WebView显示网页的更多相关文章

  1. Android 之 用WebView显示网页

    WebView可以使得网页轻松的内嵌到 app 里,还可以直接跟js相互调用. WebView有两个方法:setWebChromeClient 和 setWebClient (1) setWebCli ...

  2. Android 使用WebView显示网页

    构建WebView就可以显示Web信息.因为我觉得这里会讲述很多方式来实现WebView,所以我决定为每一种方式创建一个对应的Activity,MainActivity通过Button可以点击进入对应 ...

  3. HTML5学习总结-11 IOS 控件WebView显示网页

    一 加载外部网页 1.使用UIWebView加载网页 运行XCode  新建一个Single View Application . 2 添加安全消息 添加以下消息到项目的  Info.plist &l ...

  4. HTML5学习总结-10 Android 控件WebView显示网页

    WebView可以使得网页轻松的内嵌到app里,还可以直接跟js相互调用. webview有两个方法:setWebChromeClient 和 setWebClient 1)setWebClient: ...

  5. Android:控件WebView显示网页

    WebView可以使得网页轻松的内嵌到app里,还可以直接跟js相互调用. webview有两个方法:setWebChromeClient 和 setWebClient setWebClient:主要 ...

  6. Android:控件WebView显示网页 -摘自网络

    WebView可以使得网页轻松的内嵌到app里,还可以直接跟js相互调用. webview有两个方法:setWebChromeClient 和 setWebClient setWebClient:主要 ...

  7. WebView 显示网页

    1.布局 <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:androi ...

  8. android WebView控件显示网页

    有时需要app里面显示网页,而不调用其他浏览器浏览网页,那么这时就需要WebView控件.这个控件也是很强大的,放大,缩小,前进,后退网页都可以. 1.部分方法 //支持javascriptweb.g ...

  9. 安卓Webview缓存网页数据(无网络正常显示)

    热度 1已有 52 次阅读2016-8-26 17:53 |个人分类:常见问题|系统分类:移动开发 一.需求经历 最近的项目是一个原生 +webview 显示的 APP,一开始的时候,网站那边要求我们 ...

随机推荐

  1. JAVA - Blowfish加密出现java.security.InvalidKeyException: Illegal key size 解决方案

    最近用java进行一个blowfish的加密算法,但是在我们的eclipse上报出Illegal key size的错误.google后发现原因是:ymmetricDS加密symmetric.prop ...

  2. Linux kernel ‘uio_mmap_physical’函数缓冲区溢出漏洞

    漏洞名称: Linux kernel ‘uio_mmap_physical’函数缓冲区溢出漏洞 CNNVD编号: CNNVD-201311-154 发布时间: 2013-11-13 更新时间: 201 ...

  3. An error occurred while filtering resources

    一个比较恶心的问题.在使用过程中项目中有个错误 ,找不到原因.. An error occurred while filtering resources     Maven -> Update ...

  4. matlab添加M_map工具箱(转 http://blog.sina.com.cn/s/blog_491b86bf0100srt9.html)

    之前转载过matlab画世界地图的博文.最近正好用到.首先试了matlab自带的worldmap,感觉画出来的图形不尽如人意,比较杂乱.如下图. 略查阅了些资料,请教了Liangjing,一致推荐m_ ...

  5. Implementing Remote Validation in MVC

    Using Validation Code Step 1: Create model for Catalog table and apply the the remote validation for ...

  6. Soap UI 数据库脚本(转)

    3:在SoapUI的Test Case中新建Groovy Script连接数据库 接口如下 def sql = Sql.newInstance( 地址, 用户名, 密码, 驱动 ) 实现样例如下: i ...

  7. 解决easyui和bootstrap兼容问题

    在使用bootstrap和easyui的时候,发现很多有冲突的地方,包括datagrid控件和combo等,以下进行的问题修正,保证easyui正常显示 /*bootstrap兼容问题和easyui的 ...

  8. as3+java+mysql(mybatis) 数据自动工具(一)

    在页游中,大部分的开发模式都是:客户端(as3)+ 服务端(java)+ 数据库(mysql). 在这3个部分会有一个相同的部分就是数据结构.比如一个用户数据,在客户端使用类 UserVO(as3) ...

  9. java中的hashtable

    好久没写博客了,这次总结一下hashtable,哈希表是我们在数据结构时候所学,在网络安全时候,老师说可以用来加密,在数据库中,可以用来当作索引. http://www.cnblogs.com/leo ...

  10. nyoj 96 一个水题目

    虽然很简单,发现自己用内存太高了了,算了,我就是这水平了. 描述 已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2)位的整数,则求出w的后n-1位的数. 输入 第一行为M,表示 ...