Android WebView
来源:互联网 发布:windows怎么开发苹果 编辑:程序博客网 时间:2024/05/17 01:12
添加网络权限<uses-permission android:name="android.permission.INTERNET" />
package com.jiyun.dell.webview;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.KeyEvent;import android.webkit.WebView;import android.webkit.WebViewClient;/** * 横竖屏切换:把以下代码粘贴在 manifests(配置清单文件中) activity中 * android:screenOrientation="landscape" */public class MainActivity extends AppCompatActivity { private WebView webview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webview = (WebView) findViewById(R.id.webview); webview.loadUrl("http://www.xiaoyuanwang.com.cn"); webview.getSettings().setJavaScriptEnabled(true); webview.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { webview.loadUrl(url); return true; } });// webview.loadUrl("http://www.baidu.com"); }//如果希望浏览器后退而不是退出,需要webview 历史访问记录 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode==KeyEvent.KEYCODE_BACK){ if (webview.canGoBack()){ webview.goBack(); }else { System.exit(0); } } return true; }}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.jiyun.dell.webview.MainActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
阅读全文
0 0
- 【Android】【Webview】WebView 简介
- android WebView
- Android WebView
- Android WebView
- android webview
- Android WebView
- android WebView
- android WebView
- Android webview
- android webview
- android webview
- Android WebView
- Android WebView
- android WebView
- android webview
- android-webview
- android webview
- Webview android
- sqlzoo练习答案--SELECT from Nobel Tutorial/zh
- 星级评分原理和实现方式
- 向maven仓库中加入项目所缺的jar包
- vue懒加载
- Codeforces 343D Water Tree 题解&代码
- Android WebView
- Python之机器学习01——决策树
- Laravel Excel导出xls乱码
- 深入理解JSP原理
- 编译警告...请使用 -Xlint:deprecation 重新编译 [或-Xlint:unchecked]
- RabbitMq、ActiveMq、ZeroMq、kafka之间的比较,资料汇总
- retrofit2.0 封装
- layer弹出的iframe层在执行完毕后关闭当前弹出层
- CPU-bound(计算密集型) 和I/O bound(I/O密集型)