=================================
=================================
=================================
//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);
}
}
=================================
=================================
=================================
'스마트기기개발관련 > 안드로이드 개발' 카테고리의 다른 글
안드로이드 해상도별 기기 구분 (마켓 올릴때 참고) (0) | 2012.05.18 |
---|---|
안드로이드 마켓 필터링 (0) | 2012.05.18 |
안드로이드 java 코드로 margin값 변경하기. (0) | 2012.04.20 |
안드로이드 중간에 낀 레이아웃이 키보드와 붙어서 올라가는 효과 구조 설정해보기 (0) | 2012.04.19 |
안드로이드 가상키보드 밀지않고 그대로 올라가기 (0) | 2012.04.13 |