Android对话框仅在第二次单击时解除.为什么?
作者:互联网
为什么第一次点击时不会关闭对话框(但显示Toast)?
在第二次点击它解散(再次显示Toast).
private void networkDialog(){
final Dialog dialog = new Dialog(EnterActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog);
Button nobutton = (Button) dialog.findViewById(R.id.dialogButLeft);
nobutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Toast.makeText(getApplicationContext(), "DIALOG", Toast.LENGTH_LONG).show();
}
});
dialog.show();
}
解决方法:
试试这种方式.让我告知.我希望它会对你有所帮助.
private void networkDialog()
{
final Dialog dialog = new Dialog(EnterActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog);
Button nobutton = (Button) dialog.findViewById(R.id.dialogButLeft);
nobutton.setOnClickListener(this);
dialog.show();
}
然后使用onClick开关语句
public void onClick(View view)
{
switch (view.getId())
{
case R.id.dialogButLeft:
Toast.makeText(getApplicationContext(), "DIALOG", Toast.LENGTH_LONG).show();
dialog.dismiss();
break;
}
}
标签:android,dialog,dismiss 来源: https://codeday.me/bug/20190628/1315471.html