¾Èµå·ÎÀ̵å > Dialog
Dialog Method µé¿¡ ´ëÇؼ »ìÆ캸ÀÚ.
1. BackÅ° ´·¶À» °æ¿ì Dialog Cancle ¿©ºÎ ¼³Á¤
mDialog.setCancelable(false); // true : cancle , false : no cancle
2. Dialog È£Ãâ½Ã ¹è°æȸéÀÌ °ËÁ¤»öÀ¸·Î ¹Ù²î´Â °Í ¸·±â !
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
3. Dialog ¹ÛÀ» ÅÍÄ¡ ÇßÀ» °æ¿ì Dialog »ç¶óÁö°Ô Çϱâ
mDialog.setCanceledOnTouchOutside(true);
4. Dialog ¹ÛÀÇ View¸¦ ÅÍÄ¡ÇÒ ¼ö ÀÖ°Ô Çϱâ (´Ù¸¥ View¸¦ ÅÍÄ¡½Ã Dialog Dismiss)
mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
5. Dialog ÀÚü ¹è°æÀ» Åõ¸íÇÏ°Ô Çϱâ
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
6. Dialog Cancle½Ã Event ¹Þ±â
mDialog.setOnCancelListener(OnCancelListener listener)
7. Dialog Show½Ã Event ¹Þ±â
mDialog.setOnShowListener(OnShowListener listener)
8. Dialog Dismiss½Ã Event ¹Þ±â
mDialog.setOnDismissListener(OnDismissListener listener)
¿¹Á¦ ÄÚµå
package arabiannight.tistory.com.dialogattribute;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnShowListener;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
public class MainActivity extends Activity {
private Dialog mDialog = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createDialog();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_click:
Toast.makeText(MainActivity.this, "Activity Button ÀÔ´Ï´Ù.",
Toast.LENGTH_SHORT).show();
case R.id.btn_ok:
dismissDialog();
break;
case R.id.btn_cancle:
dismissDialog();
break;
default:
break;
}
}
private void createDialog() {
final View innerView = getLayoutInflater().inflate(R.layout.dialog, null);
mDialog = new Dialog(this);
mDialog.setTitle("Title");
mDialog.setContentView(innerView);
// BackÅ° ´·¶À» °æ¿ì Dialog Cancle ¿©ºÎ ¼³Á¤
mDialog.setCancelable(true);
// Dialog »ý¼º½Ã ¹è°æÈ¸é ¾îµÓ°Ô ÇÏÁö ¾Ê±â
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
// Dialog ¹ÛÀ» ÅÍÄ¡ ÇßÀ» °æ¿ì Dialog »ç¶óÁö°Ô Çϱâ
mDialog.setCanceledOnTouchOutside(true);
// Dialog ¹ÛÀÇ View¸¦ ÅÍÄ¡ÇÒ ¼ö ÀÖ°Ô Çϱâ (´Ù¸¥ View¸¦ ÅÍÄ¡½Ã Dialog Dismiss)
mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
// Dialog ÀÚü ¹è°æÀ» Åõ¸íÇÏ°Ô Çϱâ
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
// Dialog Cancle½Ã Event ¹Þ±â
mDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
Toast.makeText(MainActivity.this, "cancle listener",
Toast.LENGTH_SHORT).show();
}
});
// Dialog Show½Ã Event ¹Þ±â
mDialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Toast.makeText(MainActivity.this, "show listener",
Toast.LENGTH_SHORT).show();
}
});
// Dialog Dismiss½Ã Event ¹Þ±â
mDialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Toast.makeText(MainActivity.this, "dismiss listener",
Toast.LENGTH_SHORT).show();
}
});
mDialog.show();
}
private void dismissDialog() {
if(mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
}
}
}