1 布局文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
2 activity theme
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
3 SYSTEM_UI_FLAG_FULLSCREEN和SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
两个标志位都是设置全屏,区别是:
前者Activity全屏显示时, 状态栏内容隐藏覆盖掉
后者状态栏不会被隐藏覆盖,状态栏内容依然可见,延申到导航栏
4.SYSTEM_UI_FLAG_HIDE_NAVIGATION和SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
两个标志位都是设置全屏,区别是:
前者导航栏内容不显示,布局延伸到导航栏
后者导航栏内容显示,布局延伸到导航栏 ![在这里插入图片描
效果图1 设置 -设置导航栏和状态栏透明
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val decorView = window.decorView
// decorView.systemUiVisibility =View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
decorView.systemUiVisibility=View.SYSTEM_UI_FLAG_FULLSCREEN;
window.navigationBarColor=Color.TRANSPARENT;
window.statusBarColor= Color.TRANSPARENT;
setContentView(R.layout.activity_main)
}
}
总结 发现顶部状态栏和底部导航栏被黑色和白色替换掉 并且无导航栏信息 如果设置透明 则底部有个透明阴影
效果图2 设置 -导航栏和状态栏透明
class MainActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val decorView = window.decorView
decorView.systemUiVisibility =View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
window.navigationBarColor=Color.TRANSPARENT;
window.statusBarColor= Color.TRANSPARENT;
setContentView(R.layout.activity_main)
}
}
效果图3 设置 -取消底部导航栏透明
class MainActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val decorView = window.decorView
// decorView.systemUiVisibility =View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
decorView.systemUiVisibility =View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
// window.navigationBarColor=Color.TRANSPARENT;
window.statusBarColor= Color.TRANSPARENT;
setContentView(R.layout.activity_main)
}
}