最近在做一个界面需要禁止下拉状态栏,于是整理了一下,以后备用。

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;

Android 4.2 禁止下拉状态栏相关推荐

  1. Android 12.0 锁屏页面禁止下拉状态栏

    目录 1.概述 2.锁屏页面禁止下拉状态栏的核心类 3.锁屏页面禁止下拉状态栏的核心功能分析和实现

  2. android10 禁止下拉状态栏

    需求:android10 禁止下拉状态栏,也就是禁止下拉如下图的快速设置面板( Quick settings panel,也叫QS面板) 修改后:怎么拉都拉不下来,包括锁屏页面和正常桌面都无法下拉状态 ...

  3. android 4.4 禁止下拉,Android开发中禁止下拉式的实现技巧

    我们开发项目的时候,经常会看到禁止的情况,而Android开发中并没有直接调用的接口,下面是爱站技术频道小编就给大家介绍的Android开发中禁止下拉式的实现技巧,希望网友们喜欢! 分享给大家供大家参 ...

  4. Android 9.0 SystemUI 下拉状态栏快捷开关

    SystemUI 下拉状态栏快捷开关是 QSPanel,qs_panel.xml,@+id/quick_settings_panel,本篇文章就来看看这些快捷开关是如何呈现的以及如何新增一个快捷开关? ...

  5. Android 10.0 SystemUI下拉状态栏时间格式的修改(一)

    在原生的下拉状态栏时间格式为 某月某日周几 这样的格式 客户需要修改为年月日周几 某时某分这种格式 这就需要修改 显示时间的格式 在更新时间时 按照这个格式更新就可以了 首选来看 时间控件的布局文件q ...

  6. Android 10.0 SystemUI下拉状态栏UI定制化开发系列(一)

    1.概述 10.0定制化开发中,由于客户需求要求对整个SystemUI下拉状态栏和下拉通知栏部分的UI做定制,所以需要修改整个下拉状态栏的 UI布局页面,这要求对整个NotificationPanel ...

  7. Android 8.0 SystemUI下拉状态栏快捷开关

    基于工作需要,基本是在Android源生代码上进行开发,从android 5.0到现在8.0,这两年碰到各种问题发现关于Android源生发开方面的特别少.于是想着开始把遇到的.解决的问题写下来,或许 ...

  8. Monkey测试时禁止下拉状态栏

    Monkey 测试,随机点击.会下拉状态栏,关闭WiFi,打开GPS,打开蓝牙,打开飞行模式等一系列操作,严重干扰程序的测试,尤其是对网络状态下的耗电量测试. 下面的命令可以禁止 Monkey测试下, ...

  9. Android 10.0 SystemUI下拉状态栏UI定制化开发系列(八)

    目录 1.概述 2.核心代码部分 3.核心代码分析 3.1状态栏黑色透明背景的分析

最新文章

  1. 【Python算法】哈希存储、哈希表、散列表原理
  2. 20145321 《Java程序设计》第7周学习总结
  3. android中可以使用bitmap的平铺,镜像平铺等减小图片带来的apk过大的问题
  4. Java技术分享:小白如何入门Mybatis?
  5. 阶段总结——201511
  6. 花了一天精选了20多篇好文,只为与你分享
  7. [No0000D6]端口-进程查询.bat
  8. 我的世界服务器怎么弄无限急迫,我的世界有什么指令设置无限急迫
  9. cart算法_ID3、C4.5、CART决策树算法
  10. android 检测摇一摇
  11. 同一个项目的同一DLL多版本的兼容问题
  12. altium designer 2019安装教程
  13. C++通过CMD修改电脑IP地址
  14. oracle访问emp表,通过deptno查询Emp表中雇员信息(oracle)
  15. SGX 是什么技术?
  16. Hdu-5919 Sequence II(主席树在线求区间不同数)
  17. Python入门篇(二)
  18. Universal DEP/ASLR bypass with msvcr71.dll and mona.py
  19. 移动硬盘识别为本地硬盘_如果仅在硬盘已经旋转时才能识别硬盘,该怎么办?
  20. Android 内置google dialer后发现拨号后,没有通话界面显示。

热门文章

  1. 《高级软件工程》课程总结
  2. matlab失明的小猫,怎样照顾失明的猫咪
  3. vhdl具有闹钟功能的电子时钟设计
  4. HDU-2993--MAX Average Problem详解
  5. python常用函数图片_Python图像,图片处理笔记
  6. 压电式压力传感器工作原理
  7. 基于springboot实现车险理赔信息管理系统
  8. wowo - 页面回收的理解
  9. 中国联通:云计算必须开放、开源
  10. python matplotlib 画DW检验图自相关图