Android中实现沉浸式状态栏的功能
1. 先上效果图,实现沉浸式状态栏有两种方式,一种是通过写Theme主题的方式,另一种是写代码的方式。若要使多个页面出现沉浸式状态栏,则使用主题的方式更方便,如果只要使单个页面出现,则使用代码方式更好!当然了,看个人喜好而去。
2. 先来介绍写主题的方式
2.1 先在res包下新建values-v19和values-v21两个包,为了兼容Android高低版本
2.2 然后分别在包中新建styles.xml文件
2.2.1 values-v19包中styles.xml文件中的内容为:
<style name="AppTheme.TransparentStausBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item> //取消系统默认的actionBar
<item name="windowNoTitle">true</item> //取消actionBar的标题
<item name="android:windowTranslucentStatus">true</item> //允许页面可以拉伸到顶部状态栏并