注意: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);
效果图:
本文介绍了一种针对Android 4.4以上版本的应用如何实现沉浸式状态栏的方法。通过修改布局文件并使用自定义工具类,可以使应用的顶部状态栏透明并与应用界面融合。
650

被折叠的 条评论
为什么被折叠?



