Android 4.2 禁止下拉状态栏
2015-11-27 13:28
501 查看
最近在做一个界面需要禁止下拉状态栏,于是整理了一下,以后备用。
import android.app.StatusBarManager;//首先导入包StatusBarManager mStatusBar = (StatusBarManager) getSystemService(this.STATUS_BAR_SERVICE);//获得对象
mStatusBar.disable(StatusBarManager.DISABLE_EXPAND);//禁止下拉状态栏
mStatusBar.disable(StatusBarManager.DISABLE_NONE);//启用下拉状态栏(在onDestroy()添加)
//此代码只能在源码环境下才能编译
---------------------------------------------------源码中是这样定义的--------------------------------------------------------
source/frameworks/base/core/java/android/app/StatusBarManager.java
public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
public static final int DISABLE_NONE = 0x00000000;
/**
* Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
* To re-enable everything, pass {@link #DISABLE_NONE}.
*/
public void disable(int what) {
try {
final IStatusBarService svc = getService();//获得IStatusBarService 的对象
if (svc != null) {
svc.disable(what, mToken, mContext.getPackageName());//实际上使用的是IStatusBarService的disable方法
}
} catch (RemoteException ex) {
// system process is dead anyway.
throw new RuntimeException(ex);
}
}
private synchronized IStatusBarService getService() {
if (mService == null) {
mService = IStatusBarService.Stub.asInterface(
ServiceManager.getService(Context.STATUS_BAR_SERVICE));//使AIDL获取IStatusBarService对象
if (mService == null) {
Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
}
}
return mService;
}
source/frameworks/base/services/java/com/android/server/StatusBarManagerService.java
public void disable(int what, IBinder token, String pkg) {
disableInternal(mCurrentUserId, what, token, pkg);
}
private void disableInternal(int userId, int what, IBinder token, String pkg) {
enforceStatusBar();
synchronized (mLock) {
disableLocked(userId, what, token, pkg);
}
}
private void disableLocked(int userId, int what, IBinder token, String pkg) {
// It's important that the the callback and the call to mBar get done
// in the same order when multiple threads are calling this function
// so they are paired correctly. The messages on the handler will be
// handled in the order they were enqueued, but will be outside the lock.
manageDisableListLocked(userId, what, token, pkg);
final int net = gatherDisableActionsLocked(userId);
if (net != mDisabled) {
mDisabled = net;
mHandler.post(new Runnable() {
public void run() {
mNotificationCallbacks.onSetDisabled(net);
}
});
if (mBar != null) {
try {
mBar.disable(net);
} catch (RemoteException ex) {
}
}
}
}
source/frameworks/base/core/java/android/view/View.java
/**
* @hide
*
* NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
* out of the public fields to keep the undefined bits out of the developer's way.
*
* Flag to make the status bar not expandable. Unless you also
* set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
*/
public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;
相关文章推荐
- winform异型不规则界面设计的实现方法
- Android中设置只有程序第一次运行才显示的界面实现思路
- hta 实现的五子棋界面
- android开发之欢迎界面的小例子
- C#中载入界面的常用方法
- android编程实现局部界面动态切换的方法
- Android判断现在所处界面是否为home主桌面的方法
- Android编程实现泡泡聊天界面实例详解(附源码)
- android 引导界面的实现方法
- VC 界面库皮肤库相关信息珍藏
- Android中界面实现全屏显示的两种方式
- 简单做出不丑设计
- extmail 界面修改
- QT程序启动界面的使用
- The Book of Qt 4 翻译: 2.2 界面和处理逻辑的分离
- 软件界面交互和易用性改进总结
- WP7界面设计与交互指南中英译本(附下载)
- 微软发布Windows Phone 7技术预览版(多图)(1)
- wxpython笔记
- 修改SecureCRT终端的Home和End功能键