安卓开发之UIwebview

web view在安卓开发中是比较常见的UI,像微信的新闻模块就采用了这个,他的作用越来越广,下面我把以前做的贴了出来,如果有更好的办法,希望大神不吝赐教哈,嘿嘿,纯代码来了:

java代码

public class GuanYuWoMen extends Activity {

WebView webView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
setContentView(R.layout.guanyuruanjian);
WebView webview = (WebView)findViewById(R.id.web);
// WebSettings webSettings= webView.getSettings();

//支持javascript
webview.getSettings().setJavaScriptEnabled(true);
// 设置可以支持缩放
webview.getSettings().setSupportZoom(true);
// 设置出现缩放工具
webview.getSettings().setBuiltInZoomControls(true);
//扩大比例的缩放
webview.getSettings().setUseWideViewPort(true);
//自适应屏幕
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
webview.getSettings().setLoadWithOverviewMode(true);

webview.getSettings().setUseWideViewPort(true);

/*
* 加载网页进度条
* */
webview.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
//Activity和Webview根据加载程度决定进度条的进度大小
//当加载到100%的时候 进度条自动消失
GuanYuWoMen.this.setProgress(progress * 100);

ProgressBar loadingProgress=(ProgressBar)findViewById(R.id.pgs);//此控件为一个进度条控件,属于自己添加的控件这个样式是可以进行改变的
loadingProgress.setProgress(progress);
if (progress==100) {
loadingProgress.setVisibility(loadingProgress.GONE);
}
super.onProgressChanged(view, progress);

}
});
webview.loadUrl("http://www.buiqu.com/");

}
}

 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C6C6C6"
android:orientation="vertical" >

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/title_beijing" >

<ImageView
android:id="@+id/img_shezhi_fanhui"
android:layout_width="45dp"
android:background="@drawable/fanhui"
android:layout_marginLeft="5dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="#fff"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:layout_centerInParent="true"
android:text="@string/shezhi"
android:textSize="20dp" />
</RelativeLayout>

<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/layout_xiugaiphone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textSize="15sp"
android:text="@string/xiugai_phone"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:text=">"
android:textSize="18dp" />
</LinearLayout>

<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/layout_shezhianquanwenti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textSize="15sp"
android:text="@string/shezhianquanwenti"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:text=">"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/layout_guanyuwomen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >

<TextView
android:id="@+id/gywm_gywm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="15sp"
android:layout_marginLeft="5dp"
android:text="关于我们"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:text=">"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/layout_zhanghao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textSize="15sp"
android:text="@string/tuichu"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:text=">"
android:textSize="18dp" />
</LinearLayout>

<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/layout_chengxun"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >

<TextView
android:id="@+id/gywm_tcyy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="15sp"
android:layout_marginLeft="5dp"
android:text="@string/tuichuyingyong"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="right"
android:text=">"
android:textSize="18dp" />
</LinearLayout>

</LinearLayout>

原文地址:https://www.cnblogs.com/sunzan/p/4717362.html