原文地址:https://blog.csdn.net/qq_34983989/article/details/61923810
代码段:
在服务中呢,没有activity,dialog没有了依赖,那么怎么办呢? 这时,dialog就要以系统对话框的形式弹出了。在我们取得Dialog对象后,需给它设置类型,即:
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
完整代码段
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Hello,My name is Message.");
builder.setNegativeButton("CANCEL", null);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 具体操作
}
});
final Dialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();