android 간단한 Custom Dialog 예제 ( 안드로이드 커스텀 다이알로그 예제)



	//간단한 Custom 다이알로그 호출
private EventAgreeDialog mAgreeDlg;
...
mAgreeDlg = new EventAgreeDialog(mContext, mClickListener);
mAgreeDlg.show();  // Custom Dialog 호출
...

	View.OnClickListener mClickListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn_event_ok:
				if(mAgreeDlg != null){
					mAgreeDlg.dismiss();
				}
				break;
			default:
				break;
			}
			
		}
	};



/**
 * EventAgreeDialog.java
 * 다이알로그
 */
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class EventAgreeDialog extends Dialog
{
    private Context mContext = null;
    protected static final String TAG = "EventAgreeDialog";
    private TextView mTvContents = null;
    private Button mBtn_ok = null;
    private View.OnClickListener mClickListener;
    
    
    public EventAgreeDialog(Context context, View.OnClickListener clicklistener)
    {
    	super(context);
    	
//        	super(context, android.R.style.Theme_Translucent_NoTitleBar);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_event_agree);
        getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        this.setCanceledOnTouchOutside(false);		// 다이알로그 바깥영역 터치시, 다이알로그 닫히지 않기
        this.setCancelable(true); // 백키로 다이알로그 닫기
        
        mContext = context;
        mClickListener = clicklistener;
        initComponent();
        componentSetValue();
    }
    
    private void initComponent(){
    	mBtn_ok = (Button)findViewById(R.id.btn_event_ok);
    	mBtn_ok.setOnClickListener(mClickListener);	// 클릭 이벤트 등록
        mTvContents = (TextView) findViewById(R.id.tvContents);
    }
    
    private void componentSetValue(){
		String eventbody = ""고객님, 홍대점 방문을 환영합니다."
"; mTvContents.setText(Html.fromHtml(eventbody)); } @Override public void show() { super.show(); } @Override public void dismiss() { super.dismiss(); } @Override public void onBackPressed() { super.onBackPressed(); } }

// dialog_event_agree.xml 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="328dp"

    android:layout_height="wrap_content"

    android:layout_gravity="center"

    android:orientation="vertical"

    android:background="@drawable/popupbg">


    <TextView

        android:id="@+id/tvContents"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="고객님, 홍대점 방문을 환영합니다." 

        android:textSize="20dp"

        android:layout_margin="20dp"

        android:gravity="center_horizontal"

        android:visibility="visible"/>


    <Button

        android:id="@+id/btn_event_ok"

        android:layout_width="59dp"

        android:layout_height="26dp"

        android:layout_marginBottom="26dp"

        android:layout_marginTop="26dp"

        android:layout_gravity="center_horizontal|bottom"

        android:background="@drawable/bu_search2_selector"

        android:text="확인"

        android:textColor="#ffffff"

        android:textSize="18dp"

         />


</LinearLayout>


+ Recent posts