安卓WebView
来源:互联网 发布:汽车修理软件 编辑:程序博客网 时间:2024/06/05 06:44
package com.ics.aop.activity;import android.annotation.SuppressLint;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.webkit.WebChromeClient;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.ProgressBar;import com.ics.aop.ApiUrl;import com.ics.aop.R;public class WebIEactivity extends BaseActivity { // 进度条 private ProgressBar load_pro; private WebView webview; private String homeUrl = ApiUrl.API_WEBIE; private String currentUrl; private Context mContext; @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_webie); mContext = getApplicationContext(); setTitle("在线功能"); load_pro = (ProgressBar) findViewById(R.id.load_pro); webview = (WebView) findViewById(R.id.webview); // 设置WebView属性,能够执行Javascript脚本 WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); // 设置显示完整网页 settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //settings.setSupportMultipleWindows(true); webview.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (TextUtils.equals(currentUrl, homeUrl)) { view.loadUrl(url); } else { Intent secondIntent = new Intent(mContext, SecondWebActivity.class); secondIntent.putExtra("url", url); startActivity(secondIntent); } return true; } }); webview.loadUrl(homeUrl); // 显示加载进度条 webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { load_pro.setVisibility(View.GONE); } else { if (load_pro.getVisibility() == View.GONE) load_pro.setVisibility(View.VISIBLE); load_pro.setProgress(newProgress); } } }); } /*@Override public void onBackPressed() { // TODO Auto-generated method stub if (!TextUtils.equals(currentUrl, homeUrl) && webview.canGoBack()) { webview.goBack(); } else { super.onBackPressed(); } }*/}
xml文件:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/about_layout3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="40dip" android:background="@android:color/transparent" android:orientation="vertical" > <ProgressBar android:id="@+id/load_pro" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="2dip" android:max="100" android:visibility="gone" /> <WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" > </WebView> </LinearLayout></RelativeLayout>
0 0
- 安卓WebView介绍
- 安卓开发webview
- 安卓WebView
- 安卓WebView使用
- 安卓webview
- 安卓学习-WebView
- 安卓webview禁止滚动
- 安卓:WebView简单使用
- 安卓webView,js交互
- 安卓webview开发简介
- 安卓WebView使用总结
- 安卓开发 WebView基础
- 安卓app单webview改为多webview加载网页
- 安卓开发14:WebView使用
- 【安卓笔记】WebView控件使用
- 安卓 webview缓存和电话问题
- 安卓webview post传值问题
- Android(安卓)WebView设置cookie
- Type interface com.mybatis.mapper.UserMapper is not known to the MapperRegistry. 解决方法
- 琐事(三)
- javascript的简单发展过程(简到不能再简了)
- Android 5.1 添加硬件抽象层(HAL)和JNI接口总结
- mysql5.7.9主从同步配置
- 安卓WebView
- 探究android对分辨率支持以及各种类型图标尺寸大小
- Git服务器搭建全过程分步详解
- java web项目中的拦截未登录用户的问题
- (学习)高精度地震——储层分析特征(2)
- 自定义cs程序安装界面
- Activity 拥有四种基本状态
- 升级WIN10后80端口被占用
- IOS7中动态计算label的宽度和高度的方法