如何禁用Android中的通知栏下拉?

时间:2014-03-20 13:07:16

标签: android lockscreen

我正在为 Android 构建新的锁定屏幕,但我无法锁定通知栏以将其拉下来。

我想禁用通知栏下拉菜单。

3 个答案:

答案 0 :(得分:6)

    private void disablePullNotificationTouch() {
            WindowManager manager = ((WindowManager) getApplicationContext()
                    .getSystemService(Context.WINDOW_SERVICE));
            WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
            localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
            localLayoutParams.gravity = Gravity.TOP;
            localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    // this is to enable the notification to recieve touch events
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    // Draws over status bar
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

            localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            localLayoutParams.height = (int) (25 * getResources()
                    .getDisplayMetrics().scaledDensity);
            localLayoutParams.format = PixelFormat.RGBX_8888;
            customViewGroup view = new customViewGroup(this);
            manager.addView(view, localLayoutParams);
        }

//Add this class in your project
public class customViewGroup extends ViewGroup {

    public customViewGroup(Context context) {
        super(context);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        Log.v("customViewGroup", "**********Intercepted");
        return true;
    }

}

答案 1 :(得分:1)

除非您修改系统SystemUI.apk文件,否则它是不可能的,即使这样您的应用程序也需要root权限。 您可以做的最好的事情是在全屏模式下创建一个隐藏通知栏的应用程序。

答案 2 :(得分:0)

首先,您需要EXPAND_STATUS_BAR权限:

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

希望这个link能够帮到您。