安卓怎么让网页在webview打开
来源:互联网 发布:python 交易 行情平台 编辑:程序博客网 时间:2024/05/22 06:40
没事儿来一更
android使用webview加载网页
package com.example.webview;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public
class
MainActivity extends Activity
{
private
WebView webview;
@SuppressLint(
"SetJavaScriptEnabled"
)
@Override
protected
void
onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webview.getSettings();
//设置WebView属性,能够执行Javascript脚本
webSettings.setJavaScriptEnabled(
true
);
//设置可以访问文件
webSettings.setAllowFileAccess(
true
);
//设置支持缩放
webSettings.setBuiltInZoomControls(
true
);
//加载需要显示的网页
webview.loadUrl(
"http://www.baidu.com"
);
//设置Web视图
webview.setWebViewClient(
new
webViewClient ());
}
@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
//设置回退
//覆盖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
;
}
finish();
//结束退出程序
return
false
;
}
//Web视图
private
class
webViewClient extends WebViewClient {
public
boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return
true
;
}
}
}
xml代码
<?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>
阅读全文
0 0
- 安卓怎么让网页在webview打开
- 安卓使用WebView打开网页
- android 在WebView打开网页
- webview 在自己应用中打开网页
- 安卓基础:使用WebView浏览网页
- 安卓手机USB调试在哪 安卓手机怎么打开USB调试
- 使用WebView打开网页
- WebView打开网页
- WEbView打开网页错误
- 安卓app单webview改为多webview加载网页
- JS判断网页是在安卓打开还是IOS打开
- 网页在浏览器可以打开webview打不开 iOS
- Android中在控件webview中打开网页
- webview打开图库并获取安卓文件图片
- [一个星期自学安卓]手机网页空间WebView
- 安卓网络轻轻松松编程2-------下载网页,初始webView
- 安卓网络编程——webView加载有道网页
- 安卓webview快速加载网页研究提速(一级加速)
- AtCoder Grand Contest 016做题记录
- JAVA基础(一)
- Servlet——解决全站乱码问题(过滤器)
- 最小二乘法与梯度下降法
- Maven配置与项目构建
- 安卓怎么让网页在webview打开
- ubuntu 16.04内核源码编译
- EL隐藏对象
- Bash脚本条件判断和控制流结构
- 数据库笔记——Mysql、Oracle、Sqlserver || Redis、Memcached、mongoDB环境搭建
- pycaffe 搭建:常见问题解决办法
- bzoj 3864 Hero meet devil
- POJ 1845 Sumdiv 笔记
- 初识node 创建或者删除一个文件目录