布局文件
?
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <WebView android:id="@+id/wv" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout>?
主activity
?
?
package t4.mft; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; public class T4Activity extends Activity { /** Called when the activity is first created. */ WebView wv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); wv = (WebView)findViewById(R.id.wv); wv.getSettings().setJavaScriptEnabled(true); wv.setScrollBarStyle(0); wv.loadUrl("file:///android_asset/sample.html"); //在webView 加载完后 执行js wv.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url){ super.onPageFinished(view, url); wv.loadUrl("javascript:wave()"); } }); } }?
?
判断 一个 webview 是否加载完成的方法
?
?
mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { //开始 super.onPageFinished(view, url); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { //结束 super.onPageStarted(view, url, favicon); } });
?
在webview 加载中 设置背景颜色
?
?webView.setBackgroundColor(Color.parseColor("#000000"));
?
?
设置滚动条不显示
?
wv_yali.setHorizontalScrollBarEnabled(false);//水平不显示 wv_yali.setVerticalScrollBarEnabled(false); //垂直不显示?
?
?
?
?