从以下代码中创建一个单独类的自定义对话框框:
public class CustomeDialog {
Context context;
public CustomeDialog(Context context) {
this.context = context;
}
public void creatDialogBoxWihList() {
final Dialog dialog = new Dialog(context);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog_layout);
// dialog.getWindow().setBackgroundDrawable(null); //for making dialog to fill window completely
Button ok = (Button) dialog.findViewById(R.id.ok);
Button cancel = (Button) dialog.findViewById(R.id.can);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
Window window = dialog.getWindow();
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}}
在Android清单文件中添加权限
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
如果你需要帮助,请在 BroadcastReceiver 的 onReceive 函数中调用这个类。使用 link。