把一个控件长期的添加到窗口上
private void showAddress(String address){ wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.width = WindowManager.LayoutParams.WRAP_CONTENT; params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.format = PixelFormat.TRANSLUCENT; params.type = WindowManager.LayoutParams.TYPE_TOAST; params.setTitle("Toast"); tv = new TextView(this); tv.setText(address); tv.setTextSize(30f); tv.setTextColor(Color.BLUE); wm.addView(tv, params); }
想移除的话用wm.removeView(tv);