Android 禁止下拉菜单栏
如下图,有时候我们需要禁止用户下拉出菜单栏。
在解决这个问题之前,我们需要知道,下拉菜单栏总共有两种,一种是锁屏下的下拉菜单,一种是非锁屏下的下拉菜单。因此需要两种不同的方法,才能将下来菜单栏屏蔽干净。
1.屏蔽非锁屏下的下拉菜单栏
这种Android 系统其实是提供了方法的,只不过是隐藏的,只给系统应用,也就是用mk 编译的apk使用。如果第三方应用想要使用,或者Android stuido 编译方式的想要使用。则可以使用反射。
/**
* Allows an app to control the status bar.
*/
@SystemService(Context.STATUS_BAR_SERVICE)
public class StatusBarManager {
/** @hide */
public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
/** @hide */
public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
/** @hide */
public static final int DISABLE_NOTIFICATION_ALERTS
= View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
/** @hide */
@Deprecated
@UnsupportedAppUsage
public static final int DISABLE_NOTIFICATION_TICKER
= View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
/** @hide */
public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
/** @hide */
public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
/** @hide */
public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
/** @hide */
public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
/** @hide */
public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
/** @hide */
public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
/** @hide */
@Deprecated
public static final int DISABLE_NAVIGATION =
View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
/** @hide */
public static final int DISABLE_NONE = 0x00000000;
/** @hide */
public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
| DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
| DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
| DISABLE_SEARCH;
/**
* Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
* To re-enable everything, pass {@link #DISABLE_NONE}.
*
* @hide
*/
@UnsupportedAppUsage
public void disable(int what) {
try {
final int userId = Binder.getCallingUserHandle().getIdentifier();
final IStatusBarService svc = getService();
if (svc != null) {
svc.disableForUser(what, mToken, mContext.getPackageName(), userId);
}
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
}
2. 屏蔽锁屏下的下拉菜单栏
这种没有接口,只能在systemui 里面修改源码,来屏蔽掉。