1、在Style.xml文件中设置:<item name="android:windowTranslucentStatus">true</item> //透明的状态栏 <item name="android:windowTranslucentNavigation">true</item>//透明的导航图 <item name="android:fitsSystemWindows">true</item>//设置应用布局时是否考虑系统窗口布局
2、注意:在Style.xml文件中设置透明状态栏遵循的前提是:当前的SDK最小版本必须是>=19(Android4.4),否则会报错,显然这个 方法行不通,现在市场上4.4以下版本的手机还有很多,所以我们会主动放弃这种方法。
3、使用代码设置(判断当前SDK是否大于19,推荐使用代码设置)//判断SDK版本是否大于等于4.4 因为该属性只有19版本才能设置if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes(); localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);}
4、最后别忘了最重要的一步:在父布局中添加属性:android:fitsSystemWindows="true"