Android 隐藏导航栏
public void setStatusBarFullTransparent() { if (Build.VERSION.SDK_INT >= 21) {//21表示5.0 Window window = getWindow(); // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); // window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // window.setStatusBarColor(Color.TRANSPARENT); // 隐藏状态栏 getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ); // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN ); } else if (Build.VERSION.SDK_INT >= 19) {//19表示4.4 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //虚拟键盘也透明 //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } }
Android的webView唤起打印机
public void printWeb() { Log.i(TAG, "printWeb"); if (mWebView != null) { String name = mWebView.getTitle()+".pdf"; PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE); PrintAttributes.Builder builder = new PrintAttributes.Builder(); builder.setColorMode(PrintAttributes.COLOR_MODE_COLOR); printManager.print("Print", mWebView.createPrintDocumentAdapter(name), builder.build()); } }
Android & H5交互
1、Android 设置
mLayoutRoot.addView(mWebView); WebSettings mWebSettings = mWebView.getSettings(); mWebSettings.setSupportZoom(true); mWebSettings.setLoadWithOverviewMode(true); mWebSettings.setUseWideViewPort(true); mWebSettings.setDefaultTextEncodingName("utf-8"); mWebSettings.setAllowContentAccess(true); mWebSettings.setAllowFileAccess(true); mWebSettings.setAllowFileAccessFromFileURLs(false); mWebSettings.setAllowUniversalAccessFromFileURLs(false); mWebSettings.setLoadsImagesAutomatically(true); mWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //新添加,解决个别机型不兼容的问题 mWebSettings.setTextZoom(100); mWebView.getSettings().setUserAgentString(mWebView.getSettings().getUserAgentString()+"lianxin-commom-app"); //自动播放音乐 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { mWebSettings.setMediaPlaybackRequiresUserGesture(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mWebSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface mWebSettings.setJavaScriptEnabled(true); saveData(mWebSettings); newWin(mWebSettings); mWebView.setWebChromeClient(webChromeClient); mWebView.setWebViewClient(webViewClient); addJsListener(this, "NativeBridge"); mWebView.loadUrl(url);
@SuppressLint("JavascriptInterface") public void addJsListener(Object obj, String bridgeName) { mWebView.addJavascriptInterface(obj, bridgeName); }
2、js调用Android的方法
//JS调用Android方法 @JavascriptInterface public String jsCallAndroid(){ Toast.makeText(this,"JS调用Android方法成功",Toast.LENGTH_LONG).show(); return result; }
//JS调用Android方法-带参数 @JavascriptInterface public String jsCallAndroid(int type){ Toast.makeText(this,"JS调用Android方法成功,type----"+type,Toast.LENGTH_LONG).show(); return result; }
3、JS调用Android
// JS中调用Android方法
window.NativeBridge.postMessage(message);
window.NativeBridge.printWeb();
4、Android调用js
protected void pushDeviceDataToWeb(String data) { if (mWebView != null) { runOnUiThread(new Runnable() { @Override public void run() { mWebView.loadUrl("javascript:pushDeviceDataToWeb( '" + data + "')"); mWebView.loadUrl("javascript:pushDeviceDataToWebHome( '" + data + "')"); } }); } }
Android 横屏
android:screenOrientation="landscape"
标签:mWebSettings,功能,mWebView,SYSTEM,FLAG,UI,Android From: https://www.cnblogs.com/ljcgood66/p/17770629.html