❶ android商城購物車懸浮多個頁面之上怎麼實現
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);
}
}