当前位置: 首页 > 工具软件 > Collapse OS > 使用案例 >

android菜单展开收起,展开、收起状态栏 - Android社区 - https://www.androidos.net.cn/

姜业
2023-12-01

可用于点击Notifacation之后收起状态栏

public static final void collapseStatusBar(Context ctx) {

Object sbservice = ctx.getSystemService("statusbar");

try {

Class> statusBarManager = Class.forName("android.app.StatusBarManager");

Method collapse;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

collapse = statusBarManager.getMethod("collapsePanels");

} else {

collapse = statusBarManager.getMethod("collapse");

}

collapse.invoke(sbservice);

} catch (Exception e) {

e.printStackTrace();

}

}

public static final void expandStatusBar(Context ctx) {

Object sbservice = ctx.getSystemService("statusbar");

try {

Class> statusBarManager = Class.forName("android.app.StatusBarManager");

Method expand;

if (Build.VERSION.SDK_INT >= 17) {

expand = statusBarManager.getMethod("expandNotificationsPanel");

} else {

expand = statusBarManager.getMethod("expand");

}

expand.invoke(sbservice);

} catch (Exception e) {

e.printStackTrace();

}

}

 类似资料: