您可以使用标志来检查对话框是否打开,根据标志值您可以做任何您想做的事情。就像我一样。我只有一个对话框,但是当我触摸另一个对话框时EditText
,如果我的对话框被打开,那么它应该首先关闭,然后应该用动画重新打开。
代码片段:
private EditText mEditText, mEditCode;
private Dialog mDialog;
private int mClicked = 0;
private boolean isShown = false;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mEditText = (EditText)findViewById(R.id.EnterValue);
mEditText.setClickable(true);
mEditText.setOnClickListener(this);
mEditCode = (EditText)findViewById(R.id.EnterCode);
mEditCode.setClickable(true);
mEditCode.setOnClickListener(this);
}
public void onClick(View nView)
{
switch (nView.getId())
{
case R.id.EnterValue:
mClicked = R.id.EnterValue;
mEditText.requestFocus();
mEditText.setFocusableInTouchMode(false);
mEditText.setEnabled(true);
mEditText.setSelection(mEditText.getText().toString().trim().length());
if(isShown)
{
mDialog.dismiss();
showInfoDialog();
}
else
{
showInfoDialog();
}
break;
case R.id.EnterCode:
mClicked = R.id.EnterCode;
mEditCode.requestFocus();
mEditCode.setFocusableInTouchMode(false);
mEditCode.setEnabled(true);
mEditCode.setSelection(mEditCode.getText().toString().trim().length());
if(isShown)
{
mDialog.dismiss();
showInfoDialog();
}
else
{
showInfoDialog();
}
break;
}
}
private boolean showInfoDialog()
{
mDialog = new Dialog(CustomKeyboardNotLikeAndroidActivity.this, R.style.PauseDialog);
mDialog.setContentView(R.layout.keyboard);
mDialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;
mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
mDialog.setCancelable(true);
isShown = true;
mDialog.show();
return false;
}
尝试以您的方式更改此代码。希望这可以帮到你。谢谢。