标签:des android style blog http io os 使用 ar
<?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" /> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="100" android:progress="50" android:secondaryProgress="70" android:layout_gravity="center" android:visibility="gone"/> </LinearLayout>
package com.ruihuo.talk; import com.ruihuo.talk.R; import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.webkit.WebView; import android.webkit.WebViewClient; import android.net.http.SslError; import android.webkit.SslErrorHandler; import android.widget.ProgressBar; import android.widget.Toast; public class MainActivity extends Activity { /** Called when the activity is first created. */ private WebView webview; private ProgressBar myProgressBar; @SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow(); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); myProgressBar = (ProgressBar)findViewById(R.id.progressBar); myProgressBar.setIndeterminate(false); webview=(WebView)findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient() { public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){ //handler.cancel(); // Android默认的处理方式 handler.proceed(); // 接受所有网站的证书 //handleMessage(Message msg); // 进行其他处理 } public void onPageStarted(WebView webview, String url, Bitmap favicon) { super.onPageStarted(webview, url, favicon); myProgressBar.setVisibility(View.VISIBLE); } //加载完成时要做的工作 public void onPageFinished(WebView webview, String url) { super.onPageFinished(webview, url); myProgressBar.setVisibility(View.GONE); } // 加载错误时要做的工作 public void onReceivedError(WebView webview, int errorCode,String description, String failingUrl) { Toast.makeText(MainActivity.this, errorCode+ "/" + description, Toast.LENGTH_LONG) .show(); } }); //去掉横向滚动条 webview.setHorizontalScrollBarEnabled(false); //去掉垂直滚动条 webview.setVerticalScrollBarEnabled(false); //去掉百边 webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); //设置WebView属性,能够执行JavaScript脚本 webview.getSettings().setJavaScriptEnabled(true); //加载URL内容 webview.loadUrl("https://www.test.com/"); } //设置回退 public boolean onKeyDown(int keyCode,KeyEvent event) { if((keyCode==KeyEvent.KEYCODE_BACK)&&webview.canGoBack()) { webview.goBack(); return true; } return super.onKeyDown(keyCode,event); } //web视图客户端 public class MyWebViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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" /> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="100" android:progress="50" android:secondaryProgress="70" android:layout_centerInParent="true" android:visibility="visible"/> </RelativeLayout >
标签:des android style blog http io os 使用 ar
原文地址:http://www.cnblogs.com/lianxu61/p/4002155.html