我搜索一种将视图置于SwipePad之类的Android通知栏上方的方法
这就是我想要的(红色恐慌):


我已经测试了这段代码:

    setContentView(R.layout.main);

    View disableStatusBar = new View(this);
    disableStatusBar.setBackgroundColor(Color.GREEN);

    WindowManager.LayoutParams handleParams = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.FILL_PARENT,
        50,
        // This allows the view to be displayed over the status bar
        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,//or other type_system make same
        // this is to keep button presses going to the background window
        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,
        PixelFormat.TRANSLUCENT);

    handleParams.gravity = Gravity.TOP;
    getWindow().addContentView(disableStatusBar, handleParams);


但这只能给我:

绿色栏不在通知栏上方...

有人可以给我个好方法吗?

最佳答案

我用这个解决方案:

 final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            |WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            PixelFormat.TRANSLUCENT);

关于android - 在通知栏上方添加 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12466210/

10-09 07:08