感觉在显示信息时,用途还可以的。
只是不知和React Native的应用场合有何分别?
package com.tw.flag.ch13_hellowebview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
WebView wv;
ProgressBar pb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.wv);
pb = (ProgressBar)findViewById(R.id.pb);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.invokeZoomPicker();
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
pb.setProgress(progress);
pb.setVisibility(progress < 100 ? View.VISIBLE:
View.GONE);
}
});
wv.loadUrl("https://m.jd.com");
}
@Override
public void onBackPressed() {
if (wv.canGoBack()) {
wv.goBack();
return;
}
super.onBackPressed();
}
}
时间: 2024-10-27 07:23:05