添加权限
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
// 显示系统级提示框(自定义布局)
private void showNoticeDialog(String titil, final String text) {
LayoutInflater inflaterDl = LayoutInflater.from(MyApplication.getContext());
RelativeLayout layout = (RelativeLayout) inflaterDl.inflate(R.layout.layout_dialog_red_pack, null);
final Dialog builder = new AlertDialog.Builder(this).create();
builder.setCanceledOnTouchOutside(false);
builder.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);//关键句
builder.show();
builder.getWindow().setContentView(layout);
final TextView textView = (TextView) layout.findViewById(R.id.red_tv_text);
textView.setText(titil);
final ImageView img = (ImageView) layout.findViewById(R.id.red_iv_img);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}