android商城购物车悬浮多个页面之上怎么实现
发布网友
发布时间:2022-04-23 08:09
我来回答
共1个回答
热心网友
时间:2022-06-18 04:08
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WindowManager wm = (WindowManager) getApplicationContext()
.getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
// 悬浮所有页面之上
lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
// 失去焦点
lp.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
| LayoutParams.FLAG_NOT_FOCUSABLE;
TextView tv = new TextView(this);
tv.setText("我是不是你最疼爱的人,你为什么不说话,握住是你冰冷的手动也不动让我好难过");
tv.setBackgroundColor(Color.WHITE);
wm.addView(tv, lp);
}
}