ama*_*Bit 29
经过两天的搜索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_ALERT和FLAG_LAYOUT_IN_SCREEN由覆盖StatusBar.
要在顶部进行叠加StatusBar,您需要使用TYPE_SYSTEM_OVERLAY而不是TYPE_SYSTEM_ALERT.
问题是,如何获得点击/触摸?
| 归档时间: |
|
| 查看次数: |
17089 次 |
| 最近记录: |