浅谈WebView
来源:互联网 发布:iphone铃声助手 mac 编辑:程序博客网 时间:2024/04/30 21:54
- package com.android.webview.activity;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.webkit.WebView;
- public class MainActivity extends Activity {
- private WebView webview;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //实例化WebView对象
- webview = new WebView(this);
- //设置WebView属性,能够执行Javascript脚本
- webview.getSettings().setJavaScriptEnabled(true);
- //加载需要显示的网页
- webview.loadUrl("http://www.51cto.com/");
- //设置Web视图
- setContentView(webview);
- }
- @Override
- //设置回退
- //覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
- webview.goBack(); //goBack()表示返回WebView的上一页面
- return true;
- }
- return false;
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.webview.activity"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="10" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.INTERNET"/>
- </manifest>
- package com.android.webview.activity;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- public class MainActivity extends Activity {
- private WebView webview;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- webview = (WebView) findViewById(R.id.webview);
- //设置WebView属性,能够执行Javascript脚本
- webview.getSettings().setJavaScriptEnabled(true);
- //加载需要显示的网页
- webview.loadUrl("http://www.51cto.com/");
- //设置Web视图
- webview.setWebViewClient(new HelloWebViewClient ());
- }
- @Override
- //设置回退
- //覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
- webview.goBack(); //goBack()表示返回WebView的上一页面
- return true;
- }
- return false;
- }
- //Web视图
- private class HelloWebViewClient extends WebViewClient {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url);
- return true;
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <WebView
- android:id="@+id/webview"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.webview.activity"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="10" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.INTERNET"/>
- </manifest>
0 0
- 浅谈webview
- 浅谈WebView
- 浅谈WebView
- 浅谈WebView
- 浅谈WebView
- 浅谈WebView
- 浅谈WebView
- 浅谈webview
- 浅谈WebView的使用
- 浅谈Android WebView
- 浅谈WebView的使用
- 浅谈WebView的使用
- Android 系列:浅谈WebView
- 浅谈WebView的使用
- 浅谈WebView的使用
- Android:浅谈WebView
- 浅谈WebView的使用
- 浅谈WebView的使用
- MySQL命令大全
- java 反射调用 私有构造类中 private static final 属性的方法
- Android中Activity四种启动模式详解
- ubuntu常用包管理命令
- iOS tintColor与backgroundColor
- 浅谈WebView
- 大数据笔试面试问题之分治法解决
- iOS详细讲解沙盒机制
- JS判断文本框内容改变事件的简单实例
- HTTP协议详解
- dom修改
- iOS 开发 屏幕尺寸 --------开发者必备
- [Python]输出中文报错的解决方法
- 开源、高效、跨平台:深剖Google FlatBuffers工作原理