在状态栏上方显示视图?

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

我知道你可以从一个视图的状态栏的下方alignment父视图。 但是,你将如何看到状态栏的顶部?

Solutions Collecting From Web of "在状态栏上方显示视图?"

@Sadeshkumar的答案是不正确的ICS和以上(也许GB)。

StatusBar覆盖了使用TYPE_SYSTEM_ALERTFLAG_LAYOUT_IN_SCREEN创build的视图。

要在StatusBar顶部获得叠加层,您需要使用TYPE_SYSTEM_OVERLAY而不是TYPE_SYSTEM_ALERT

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

禁用系统状态栏 – 没有根


经过两个整天searchSOpost和反复阅读Android文档..这是我想出的解决scheme。 (testing)

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

不要忘记权限:

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

注意:
testing了kitkat。

StatusBar覆盖了由TYPE_SYSTEM_ERRORFLAG_LAYOUT_IN_SCREEN创build的视图。

  int statusBarHeight = (int) Math.ceil(25 * getResources().getDisplayMetrics().density); View statusBarView = new View(MyActivity.this); statusBarView.setBackgroundColor(Color.GREEN); WindowManager.LayoutParams params = null; params = new WindowManager.LayoutParams(WindowManager.LayoutParams.FILL_PARENT,statusBarHeight,WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT); params.gravity = Gravity.RIGHT | Gravity.TOP; WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(statusBarView, params);