如果你想做一些不寻常的东西像创建浮动窗口并且不要填满屏幕。如果您想创建一个在其他应用程序前面可见的浮动窗口,则不能使用Activity,因为当另一个应用程序到达前台时,您的Activity将停止,其窗口将被隐藏或销毁。相反,您需要从后台服务显示窗口。
WindowManager.LayoutParams p = new WindowManager.LayoutParams( // Shrink the window to wrap the content rather than filling the screen WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, // Display it on top of other application windows, but only for the current user WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, // Don't let it grab the input focus WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, // Make the underlying application window visible through any transparent parts PixelFormat.TRANSLUCENT);// Define the position of the window within the screenp.gravity = Gravity.TOP | Gravity.RIGHT;p.x = 0;p.y = 100;WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);windowManager.addView(myView, p);需要添加权限
<uses-permission android:name=”android.permission.SYSTEM_ALERT_WINDOW”/>
新闻热点
疑难解答