直播带货源码,渐变式状态栏的不同写法
直播带货源码,渐变式状态栏的不同写法
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>
以上就是 直播带货源码,渐变式状态栏的不同写法,更多内容欢迎关注之后的文章
浙公网安备 33010602011771号