如何在Android中实现悬浮Activity
2016-07-08 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
WindowManager wm;
WindowManager.LayoutParams wmlp;
LinearLayout linear;
EditText t;
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wmlp = new WindowManager.LayoutParams();
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
wmlp.gravity = Gravity.TOP|Gravity.LEFT;
wmlp.format = PixelFormat.RGBA_8888;
wmlp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_FULLSCREEN|WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
wmlp.x = 0;//悬浮窗左上角的x坐标
wmlp.y = 0;//悬浮窗左上角的坐标
wmlp.width = 50;//宽
wmlp.height = 30;//高
linear = new LinearLayout(getApplicationContext());//悬浮窗显示的布局
linear.setGravity(Gravity.BOTTOM|Gravity.LEFT);
//组件
t = new TextView(getApplicationContext()); //文本
t.setTextColor(Color.RED);//文本颜色
t.setText("哈哈");
linear.addView(t);//将textview添加进布局
wm.addView(linear,wmlp); // 窗口管理器添加这个部件
WindowManager.LayoutParams wmlp;
LinearLayout linear;
EditText t;
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wmlp = new WindowManager.LayoutParams();
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
wmlp.gravity = Gravity.TOP|Gravity.LEFT;
wmlp.format = PixelFormat.RGBA_8888;
wmlp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_FULLSCREEN|WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
wmlp.x = 0;//悬浮窗左上角的x坐标
wmlp.y = 0;//悬浮窗左上角的坐标
wmlp.width = 50;//宽
wmlp.height = 30;//高
linear = new LinearLayout(getApplicationContext());//悬浮窗显示的布局
linear.setGravity(Gravity.BOTTOM|Gravity.LEFT);
//组件
t = new TextView(getApplicationContext()); //文本
t.setTextColor(Color.RED);//文本颜色
t.setText("哈哈");
linear.addView(t);//将textview添加进布局
wm.addView(linear,wmlp); // 窗口管理器添加这个部件
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询