简单的页面跳转

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. 阿里巴巴SUI Mobile的使用

    1.引入文件 <link rel="stylesheet" href="./css/sm.min.css"> <link rel=" ...

  2. API函数

    1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同 ...

  3. Linux内核与根文件系统的关系

    开篇题外话:对于Linux初学者来说,这是一个很纠结的问题,但这也是一个很关键的问题!         一语破天机: “尽管内核是 Linux 的核心,但文件却是用户与操作系统交互所采用的主要工具.这 ...

  4. 教程 打造OS X Mavericks原版 EFI Clover 引导安装

    自从 Mavericks 10.9 发布DP版到现在的GM版以来,以前Clover引导原版InstallESD.dmg方式安装原版的方法已经不能使用,而且已经不能引导安装了,所以从GM版发布以前,终于 ...

  5. c语言字符类别测试库函数#include<ctype.h>

    字符类测试<ctype.h> 头文件<ctype.h>中说明了一些用于测试字符的函数.每个函数的变量均为int类型,变量的值必须是EOF或可用unsigned char类型表示 ...

  6. ruby编程语言-学习笔记4(第4章 表达式和操作符)

    4.6.9 范围  Flip-Flops:  ..和... ..和... 操作符不是基于方法的,无法重定义.(优先级比较低) x+1 .. x*x   #可以认为是x+1 至 x*x 的范围 因为操作 ...

  7. remove all event handlers from a control

    The sample code below will remove all Click events from button1 public partial class Form1 : Form { ...

  8. Jmeter初步使用二--使用jmeter做一个简单的性能测试

    经过上一次的初步使用,我们懂得了Jmeter的安装与初步使用的方法.现在,我们使用Jmeter做一个简单的性能测试.该次测试,提交的参数不做参数化处理,Jmeter各元件使用将在介绍在下一博文开始介绍 ...

  9. UVa11404 - Palindromic Subsequence(区间DP+打印路径)

    题目大意 给定一个字符串,要求你删除尽量少的字符,使得原字符串变为最长回文串,并把回文串输出,如果答案有多种,则输出字典序最小的 题解 有两种解法,第一种是把字符串逆序,然后求两个字符串的LCS,并记 ...

  10. Apple LLVM 6.0 Warning: profile data may be out of date

    I have no clue what this meant, so I googled the problem. I only ended up with some search results s ...