纯粹是个人学习总结,如有不对的地方请吐槽。
//在dialog show方法之前添加如下代码,表示该dialog是一个系统的dialog
dialog.getWindow().setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
测试代码:
Builder builder = new AlertDialog.Builder(this);
builder.setTitle("提示");
builder.setMessage("在service中打开的dialog");
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
final AlertDialog dialog = builder.create();
//在dialog show方法之前添加如下代码,表示该dialog是一个系统的dialog**
dialog.getWindow().setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
new Thread(){
public void run() {
SystemClock.sleep(4000);
hanlder.post(new Runnable() {
@Override
public void run() {
dialog.show();
}
});
};
}.start();
}