Google 在 4.4 给全屏阅读文字或玩游戏这种情景增长了透明状态栏和透明导航栏的功能java
方法1:设置 Acitivity 所在 window 的属性android
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } setContentView(R.layout.activity_main); }
若是 Activity 有 actionbar,那么还须要在 Activity 的布局文件的根节点上设置两个属性ide
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="true" android:fitsSystemWindows="true" android:orientation="vertical" tools:context="com.example.statusbar.MainActivity" >
方法2:设置 theme 属性
布局
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor" android:theme="@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor" android:theme="@android:style/Theme.Holo.NoActionBar.TranslucentDecor"
若是使用自定主题,只需在在 values-19 文件夹下添加如下属性spa
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar" > <!-- API 19 theme customizations can go here. --> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style>
效果以下图所示:code