1、实现代码
public static void collapseStatusBar(Context context) {
Object service =context.getSystemService("statusbar");
if (null == service)
return;
try {
Class<?> clazz = Class.forName("android.app.StatusBarManager");
int sdkVersion = android.os.Build.VERSION.SDK_INT;
Method collapse = null;
if (sdkVersion <= 16) {
collapse = clazz.getMethod("collapse");
} else {
collapse = clazz.getMethod("collapsePanels");
}
collapse.setAccessible(true);
collapse.invoke(service);
} catch (Exception e) {
e.printStackTrace();
}
}
2、权限
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
网友评论