我有一个对话框窗口,它必须包含容器和两个单击侦听器才能关闭对话框,我希望我只显示一次,我使用此代码,但它根本不显示!
有什么帮助吗?
SharedPreferences setting = getSharedPreferences("dialogprefs", 0); final SharedPreferences.Editor editor = setting.edit(); { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.setContentView(R.layout.hint1); dialog.setCanceledOnTouchOutside(true); dialog.setTitle("Hint"); View masterView = dialog.findViewById(R.id.LinearLayout1); masterView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); editor.putString("dialogshow", "0".toString()); editor.commit(); } }); View masterView1 = dialog.findViewById(R.id.imageView1); masterView1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); editor.putString("dialogshow", "0".toString()); editor.commit(); } }); if (setting.getString("dialogshow" , "0").equals("0")) { dialog.dismiss(); } else { dialog.show(); } }