显示状态栏上方的视图?

use*_*019 10 eclipse android view statusbar

我最近看到了一个应用程序的图像,该应用程序能够在状态栏上方显示视图,并且还能够以视图覆盖它.

我知道您可以从状态栏下方的对齐父级顶部的视图中获取视图.但是如何在状态栏上方查看?

ama*_*Bit 29

禁用系统状态栏 - 没有Root


经过两天的搜索SO帖子并一遍又一遍地阅读Android文档.这是我想出的解决方案.(测试)

    mView= new TextView(this);                                       
    mView.setText(".........................................................................");                       

    mLP = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            100,
            // Allows the view to be on top of the StatusBar
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
            // Keeps the button presses from going to the background window
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            // Enables the notification to recieve touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            // Draws over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);

    mLP.gravity =  Gravity.TOP|Gravity.CENTER;      

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    mWindowManager.addView(mView, mLP);
Run Code Online (Sandbox Code Playgroud)

别忘了权限:

<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
Run Code Online (Sandbox Code Playgroud)

注意:
测试到kitkat.


log*_*ray 12

@Sadeshkumar的答案对于ICS及以上(也许是GB)是不正确的.

视图与创建TYPE_SYSTEM_ALERTFLAG_LAYOUT_IN_SCREEN由覆盖StatusBar.

要在顶部进行叠加StatusBar,您需要使用TYPE_SYSTEM_OVERLAY而不是TYPE_SYSTEM_ALERT.

问题是,如何获得点击/触摸?


小智 6

视图与创建TYPE_SYSTEM_ERRORFLAG_LAYOUT_IN_SCREEN由覆盖StatusBar.