注意:Android版本 > 4.4此方法有效
第一步:
在Activity的布局文件中,根布局中加入以下第5-7行代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/titlebar"
android:clipToPadding="true"
android:fitsSystemWindows="true"
android:orientation="vertical" >
</LinearLayout>
第二步:
新建类KitkatUtils.class:
package cn.powerthink.djt.utils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.WindowManager;
public class KitkatUtils {
@SuppressLint("InlinedApi")
public static void KITKAT(Context mContext) {
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
((Activity)mContext).getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
((Activity)mContext).getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
}
第三步:
在需要的地方调用即可:
KitkatUtils.KITKAT(this);
效果图: