一、设置状态栏为透明
1、屏蔽.fitsSystemWindows(true)
<?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="lianxin.web.psybot.nexring.MainActivity"> <include layout="@layout/content_main" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> <!-- android:fitsSystemWindows="true"--> <!-- .fitsSystemWindows(true) //解决状态栏和布局重叠问题,任选其一,默认为false,当为true时一定要指定statusBarColor(),不然状态栏为透明色,还有一些重载方法-->
2、设置状态栏的字体颜色为黑色
// 设置状态栏 if (Build.VERSION.SDK_INT >= 21) { val decorView = window.decorView decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE var originVisibility: Int = decorView.getSystemUiVisibility() if ( originVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == 0) { originVisibility = originVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR } decorView.setSystemUiVisibility(originVisibility) window.statusBarColor = Color.TRANSPARENT }
二、向下取整,向上取整,四舍五入
val number = 3.75 val result = floor(number) // 调用floor()函数对number进行向下取整 println("结果为:$result") // 输出结果为3.0
val number = 3.14 val roundedNumber = ceil(number) // 将小数部分四舍五入到最接近的大于或等于该值的整数 println("向上取整后的结果为:$roundedNumber")
val number = 3.145926 val roundedNumber = number.round() // 结果为3 println(roundedNumber)
三、获取时间戳
// Calendar 是this var dateTime : Long = this.getTimeInMillis();
四、webView加载
// 设置webView============================================================================== messageHandler = MessageHandler() binding.webView.webViewClient = WebViewClient() binding.webView.settings.javaScriptEnabled=true; binding.webView.settings.setSupportZoom(false) // 支持缩放 默认为true 是下面那个的前提 binding.webView.settings.builtInZoomControls = false // 设置内置的缩放控件 若为false 则该WebView不可缩放 binding.webView.settings.displayZoomControls = false // 隐藏原生的缩放控件 binding.webView.settings.cacheMode = WebSettings.LOAD_DEFAULT // 缓存模式 binding.webView.settings.domStorageEnabled = true // 启用或禁用DOM缓存 binding.webView.settings.setSupportMultipleWindows(false) // 设置WebView是否支持多窗口 // 设置自适应屏幕, 两者合用 binding.webView.settings.useWideViewPort = true // 将图片调整到适合webview的大小 binding.webView.settings.loadWithOverviewMode = true // 缩放至屏幕的大小 binding.webView.settings.allowFileAccess = true // 设置可以访问文件 binding.webView.settings.setGeolocationEnabled(true) // 是否使用地理位置 binding.webView.fitsSystemWindows = true binding.webView.setLayerType(View.LAYER_TYPE_HARDWARE,null) binding.webView.loadUrl("https://xxx") //Kotlin与H5通信方式1: H5调用Kotlin方法 //设置Kotlin与H5通信桥梁类 binding.webView.addJavascriptInterface(this,"NativeBridge") // 返回上一层 binding.webView.setOnKeyListener { view, keyCode, keyEvent -> if (keyEvent.action == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && binding.webView.canGoBack()) { binding.webView.goBack() return@setOnKeyListener true } } return@setOnKeyListener false } // 设置webView==============================================================================
标签:功能,val,settings,kotlin,binding,number,Android,true,webView From: https://www.cnblogs.com/ljcgood66/p/17989192