部分代码如下:
public void ShowAlertScreen(Context context,String titles,String content,String phone)
{
// 获取Service
wm = (WindowManager) context.getSystemService("window");
WindowManager.LayoutParams mWindowParams = new WindowManager.LayoutParams();
// 设置窗口类型,一共有三种Application windows, Sub-windows, System windows
// API中以TYPE_开头的常量有23个
mWindowParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
// 设置期望的bitmap格式
mWindowParams.format = PixelFormat.RGBA_8888;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
// 以下属性在Layout Params中常见重力、坐标,宽高
//mWindowParams.gravity = Gravity.LEFT | Gravity.TOP;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.activity_call_label, null);
TextView tv =(TextView) view.findViewById(R.id.txtPhone);
tv.setText(phone);
TextView title = (TextView) view.findViewById(R.id.txtTitle);
TextView alert = (TextView) view.findViewById(R.id.txtAlert);
ImageButton btnClose = (ImageButton) view.findViewById(R.id.btnJb2);
if(!titles.equals(""))
{
title.setText(titles);
}
alert.setText(content);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try
{
// 获取Service
AlertDialog.Builder builder = new AlertDialog.Builder(FireWallService.this);
builder.setTitle("请选择举报类型") // title
.setItems(R.array.stype, new DialogInterface.OnClickListener() { //content
@Override
public void onClick(DialogInterface dialog, int which) {
wType = (which+1)+"";
new Thread() {
@Override
public void run()
{
WebClassCommonEntity result = new WebUtil().markPhone(getApplicationContext(),Configuration.imei,phone_num,wType);
}
}.start();
}});
AlertDialog ad = builder.create();
//ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); //系统中关机对话框就是这个属性
ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
ad.show();
}
catch(Exception eee)
{
}
}
});
// 添加指定视图
wm.addView(view, mWindowParams);
}
原文:http://www.cnblogs.com/virgilko/p/4643405.html