不用手下拉,直接用代码来操作实现下拉状态栏的功能,用反射来实现:
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();
}
}
引用地址:https://gist.github.com/GiitSmile/47a1bbd01b39bb9c9b64
请关注我的微信公众号~
![](http://upload-images.jianshu.io/upload_images/1857762-b6879876b430826c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)