我搜索一种方法将视图放在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);
但这只会给我:
绿栏不在通知栏上方......
任何人都可以给我一个好方法吗?
答案 0 :(得分: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);
答案 1 :(得分:-3)
如果您的意思是想要通知栏中的图标,则可以使用NotificationManager类。