스마트기기개발관련/안드로이드 개발

안드로이드 팝업(popup Dialog) 다이얼로그 입맛대로 구성 관련(PopupWindow, AlertDialog 등등)

AlrepondTech 2012. 4. 23. 16:27
반응형

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

//popup xml 구성 파일이름: cchatpopup.xml //출처 http://202psj.tistory.com

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ff22272d" >

    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:textSize = "22sp"
        android:gravity = "center"
        android:text="타이틀"
        android:textColor="#ffffffff"
        />
                 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity = "center"
    android:background="#ff22272d" >
   
       
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:orientation="vertical"
    android:gravity = "center"
    android:background="#ff22272d" >
   
         <Button
             android:id="@+id/close"   
             android:layout_width="64dip"
             android:layout_height="36dip"
             android:layout_marginTop="6dip"
             android:text="종료"/>
        
    </LinearLayout>
       
    </LinearLayout>
   
  
   
</LinearLayout>

 

 

 

 

=================================

=================================

=================================

 

 




//PopupWindow setting //출처 http://202psj.tistory.com


public class CChatPopup extends PopupWindow{
   
    protected CTitleBar _titlebar = null;
    protected CChatPopupList _list = null;
    int _type = 0;
       
    public static CChatPopup show(Activity act, View view, int type)
    {
        //
        //-------------------------------------------------
        Resources res = act.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
   
        int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 380, dm);
        int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm);
       
        int dlgX = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, dm);
        int dlgY = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, dm);
      
        View popupView = View.inflate(act, R.layout.cchatpopup, null);
        CChatPopup pop = new CChatPopup(popupView,width,height,true, type);
        pop.showAtLocation(view, Gravity.RIGHT,dlgX,dlgY);
       
        Drawable shape = res.getDrawable(R.drawable.drawdlground);
        popupView.setBackgroundDrawable(shape);
       
        return pop;
    }
   
    public CChatPopup(View contentView,int width,int height,boolean focusable, int type)
    {
        super(contentView, width, height, focusable);
       
        _type = type;
       
        initGUI();
    }

    void initGUI()
    {
        //show에서 xml에서 받은 ui view 가 getContentView()으로 반영 된다.

        String closeStr = "닫기"; //닫기 버튼 이름 서정
       
        //close
        Button btn = (Button)getContentView().findViewById(R.id.close);
        btn.setText(closeStr);
        btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dismiss();
            }
        });
       
         TextView title = (TextView)getContentView().findViewById(R.id.title);
         String titleStr = "커스텀 팝업"; //타이틀이름 설정
         title.setText(titleStr);

    }

}

 

 

 

=================================

=================================

=================================

 

 


//AlertDialog setting //출처 http://202psj.tistory.com
/*
public class CChatPopup2 extends AlertDialog{
   
    protected CTitleBar _titlebar = null;
    protected CChatPopupList _list = null;
    int _type = 0;
   
    public static void show(CBaseActivity act, View view, int type)
    {
        Resources res = act.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
   
        int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 380, dm);
        int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm);
       
        int dlgX = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 410, dm);
        int dlgY = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, dm);
   
     
        CChatPopup2 pop = new CChatPopup2(act, type);
        pop.show();
       
   
        LayoutParams params = pop.getWindow().getAttributes();
        params.x = dlgX;
        params.y = dlgY;
        params.width = width;
        params.height = height;
        pop.getWindow().setAttributes(params);
    }
   
    public static void show(Activity act, View view, int type)
    {
        Resources res = act.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
   
        int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 380, dm);
        int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm);
       
        int dlgX = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 410, dm);
        int dlgY = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, dm);
   
     
        CChatPopup2 pop = new CChatPopup2(act, type);
        pop.show();
       
   
        LayoutParams params = pop.getWindow().getAttributes();
        params.x = dlgX;
        params.y = dlgY;
        params.width = width;
        params.height = height;
        pop.getWindow().setAttributes(params);
    }
   
    protected CChatPopup2(Context context, int type) {
        super(context);
        // TODO Auto-generated constructor stub
        _type = type;
        initGUI();
    }
   
    protected CChatPopup2(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        initGUI();
    }

    void initGUI()
    {
        View popupView = View.inflate(getContext(), R.layout.cchatpopup, null);
        setView(popupView, 0, 0, 0, 0);
       
        //show에서 xml에서 받은 ui view 가 getContentView()으로 반영 된다.

        //close
        String closeStr = "닫기"; //닫기버튼 이름
        Button btn = (Button)popupView.findViewById(R.id.close);
        btn.setText(closeStr);
       
        btn.setOnClickListener(new View.OnClickListener() {
           
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dismiss();
            }
        });
       
       
        TextView title = (TextView)popupView.findViewById(R.id.title);
        String titleStr = "커스텀 팝업"; // 내가 xml 에 지정한 타이틀 이름 설정
    
        title.setText(titleStr);
       
    }
}

 

 

=================================

=================================

=================================

 

 




반응형