2

我搜索了一种将视图放在 Android 通知栏上方的方法,例如 SwipePad 这就是我想要的(红色恐慌): 在此处输入图像描述

我已经测试了这段代码:

    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);

但这只会给我:在此处输入图像描述

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

任何人都可以给我一个好方法吗?

4

2 回答 2

0

我使用这个解决方案:

 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);
于 2018-10-30T09:00:01.857 回答
-3

如果您的意思是要在通知栏中显示一个图标,则可以使用NotificationManager类。

于 2012-09-17T19:59:33.557 回答