안드로이드/Android Custom Dialog 만들기
TestCustomDialogActivity.Java
CustomDialog.Java
TestCustomDialogActivity.Java
package arabiannight.tistory.com; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Toast; import arabiannight.tistory.com.popup.CustomDialog; public class TestCustomDialogActivity extends Activity { private CustomDialog mCustomDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onClickView(View v){ switch (v.getId()) { case R.id.bt_main: mCustomDialog = new CustomDialog(this, "8월의 크리스마스!!", "영화보러가자~!!!", leftClickListener, rightClickListener); mCustomDialog.show(); break; } } private View.OnClickListener leftClickListener = new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "왼쪽버튼 Click!!", Toast.LENGTH_SHORT).show(); } }; private View.OnClickListener rightClickListener = new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "오른쪽버튼 Click!!", Toast.LENGTH_SHORT).show(); } }; }
CustomDialog.Java
package arabiannight.tistory.com.popup; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.TextView; import arabiannight.tistory.com.R; public class CustomDialog extends Dialog{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WindowManager.LayoutParams lpWindow = new WindowManager.LayoutParams(); lpWindow.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND; lpWindow.dimAmount = 0.8f; getWindow().setAttributes(lpWindow); setContentView(R.layout.custom_dialog); setLayout(); setTitle(mTitle); setContent(mContent); setClickListener(mLeftClickListener , mRightClickListener); } public CustomDialog(Context context) { // Dialog 배경을 투명 처리 해준다. super(context , android.R.style.Theme_Translucent_NoTitleBar); } public CustomDialog(Context context , String title , View.OnClickListener singleListener) { super(context , android.R.style.Theme_Translucent_NoTitleBar); this.mTitle = title; this.mLeftClickListener = singleListener; } public CustomDialog(Context context , String title , String content , View.OnClickListener leftListener , View.OnClickListener rightListener) { super(context , android.R.style.Theme_Translucent_NoTitleBar); this.mTitle = title; this.mContent = content; this.mLeftClickListener = leftListener; this.mRightClickListener = rightListener; } private void setTitle(String title){ mTitleView.setText(title); } private void setContent(String content){ mContentView.setText(content); } private void setClickListener(View.OnClickListener left , View.OnClickListener right){ if(left!=null && right!=null){ mLeftButton.setOnClickListener(left); mRightButton.setOnClickListener(right); }else if(left!=null && right==null){ mLeftButton.setOnClickListener(left); }else { } } private TextView mTitleView; private TextView mContentView; private Button mLeftButton; private Button mRightButton; private String mTitle; private String mContent; private View.OnClickListener mLeftClickListener; private View.OnClickListener mRightClickListener; /* * Layout */ private void setLayout(){ mTitleView = (TextView) findViewById(R.id.tv_title); mContentView = (TextView) findViewById(R.id.tv_content); mLeftButton = (Button) findViewById(R.id.bt_left); mRightButton = (Button) findViewById(R.id.bt_right); } }
'Android > Dialog' 카테고리의 다른 글
안드로이드/Android Handler를 사용한 ProgressDialog 띄우기 (1) | 2012.06.28 |
---|---|
안드로이드/Android 다이얼로그 안에서 onClick() 메서드 안에서 Activity finish() 호출 하기 (0) | 2012.06.22 |
안드로이드/Android 기본 Dialog, inflate Dialog (1) | 2012.03.29 |
안드로이드/Android "잠시만 기다려 주세요." ProgressDialog 띄우기 (2) | 2012.01.27 |
안드로이드/Android Inflater 적용한 Alertdialog 만들기 (2) | 2011.12.03 |