androidwebviewvue不显示
(2023-09-29 19:18:45)分类: androidios |
转:https://github.com/ghost60/android-webview-vue
android-webview-vue
使用vue开发webapp,通过android的webview嵌入到android APP中
需要配置的项
在android项目的layout中引入webvie
在java类中设置webview,进行js交互
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
//页面开始加载时
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
//页面加载结束时
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
// 这里进行无网络或错误处理,具体可以根据errorCode的值进行判断,
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.set;// 支持JS
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //设置缓存
webSettings.set;//支持通过js打开新的窗口
webSettings.setBuiltInZoomControls(false);// 设置支持缩放
webSettings.setDomStorageEnabled(true);//使用localStorage则必须打开
webSettings.setSupportMultipleWindows(false);// 设置同一个界面
webSettings.setNeedInitialFocus(false);// 禁止webview上面控件获取焦点(黄色边框)
webSettings.setDatabaseEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setSupportZoom(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
webSettings.setUseWideViewPort(true);
// mWebView.setBackgroundColor(ContextCompat.getColor(this,android.R.color.transparent));
// mWebView.setBackgroundResource(R.color.colorAccent);
// REMOTE RESOURCE
// mWebView.loadUrl("http://www.baidu.com");
// mWebView.setWebViewClient(new MyWebViewClient());
//忽略跨域
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}else{
try {
Class
前一篇:Android系统是自带分享功能
后一篇:如何一键制作全套安卓logo图