直播帶貨原始碼,漸變式狀態列的不同寫法
阿新 • • 發佈:2022-04-21
直播帶貨原始碼,漸變式狀態列的不同寫法
if(Build.VERSION.SDK_INT > 21){
setStatusBarView()
}
private fun setStatusBarView() {
//延時載入資料,保證Statusbar繪製完成後再findview。
Looper.myQueue().addIdleHandler {
setStatusBarDrawable(this,R.drawable.home_top_gradient_bg)
window.decorView.addOnLayoutChangeListener(
View.OnLayoutChangeListener { view, i, i2, i3, i4, i5, i6, i7, i8 ->
setStatusBarDrawable(this,R.drawable.home_top_gradient_bg)
}
)
false
}
}
private fun setStatusBarDrawable(activity: AppCompatActivity,id:Int){
//利用反射機制修改狀態列背景
val identifier = activity.resources.getIdentifier("statusBarBackground", "id", "android")
val statusBarView: View = activity.window.findViewById(identifier)
if (statusBarView != null) {
statusBarView.setBackgroundResource(id)
}
}
漸變式drawable資原始檔
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="180"
android:endColor="#2c79e2"
android:centerColor="#07C160"
android:startColor="#00FF00"
android:type="linear" />
</shape>
以上就是 直播帶貨原始碼,漸變式狀態列的不同寫法,更多內容歡迎關注之後的文章