在活动的onCreate()方法里加入如下代码即可实现预留状态栏位置,(注意一旦风格被设置为全屏下面的方法将失效)
ViewGroup mContentView = (ViewGroup) findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
//注意不是设置 ContentView 的 FitsSystemWindows, 而是设置 ContentView 的第一个子 View . 使其不为系统 View 预留空间.
//设置为true表示为状态栏预留空间。
ViewCompat.setFitsSystemWindows(mChildView, true);
}