WebView的简单使用
来源:互联网 发布:分布式数据库 hadoop 编辑:程序博客网 时间:2024/05/18 05:53
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.webview.MainActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /></RelativeLayout>
package com.example.webview;import android.app.ProgressDialog;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.webkit.WebChromeClient;import android.webkit.WebResourceRequest;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;public class MainActivity extends AppCompatActivity {private String url="http://2014.qq.com/"; private WebView webView; private ProgressDialog progressDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);// Uri uri=Uri.parse(url);// Intent intent=new Intent(Intent.ACTION_VIEW,uri);// startActivity(intent); webView= (WebView) findViewById(R.id.webview);// webView.loadUrl("file:///android_layout/layout.xml"); webView.loadUrl("http://www.baidu.com"); WebSettings webSettings=webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.setWebChromeClient(new WebChromeClient(){ @Override public void onProgressChanged(WebView view, int newProgress) { if(newProgress==100) { closeDialog(); } else{ openDialog(newProgress); } } });// webView.setWebViewClient(new WebViewClient(){// @Override// public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {// view.loadUrl(url);// return true;// }// }); } private void closeDialog() { if(progressDialog!=null&&progressDialog.isShowing()) { progressDialog.dismiss(); progressDialog=null; } } private void openDialog(int newProgress) { if(progressDialog==null) { progressDialog=new ProgressDialog(MainActivity.this); progressDialog.setTitle("正在加载"); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgress(newProgress); progressDialog.show(); } else { progressDialog.setProgress(newProgress); } }}
0 0
- 简单webview的使用
- 简单WebView的使用
- WebView的简单使用
- WebView简单的使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- webview的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- WebView的简单使用
- C语言学习:数据类型
- HTTP协议状态码详解(HTTP Status Code)
- Spring加载properties文件的两种方式
- 黑马程序员:C/C++学习路线图已上线!一图在手,天下我有!
- iOS 跳转到地图App后的各种操作
- WebView的简单使用
- Vuforia开发高阶二-虚拟按钮(第二部分)
- html表格标签使用
- 二维树状数组
- hexo+github搭建博客
- [Extjs6]清除数组内容
- 教你如何在Android 6.0上创建系统悬浮窗
- (Unity3d)Vuforia开发高阶二-虚拟按钮
- 去除桌面的svn问号标志符