pop-up dialog
public void createPopupDialog() {//레이아웃 가져다 씀
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
LinearLayout layout = new LinearLayout(context);
Dialog dialog = new Dialog(context);
// 다이어 로그의 크기를 정한다.
LinearLayout.LayoutParams dialogParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
dialogParams.width = display.getWidth() * 1000 / 1080;
dialogParams.height = display.getHeight() * 1300 / 1844;
LinearLayout dialoglayout = new LinearLayout(context);
dialoglayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
dialoglayout.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
layout.setLayoutParams(dialogParams);
layout.setBackgroundResource(R.drawable.boxline);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setAnimation(null);
WebView webview_popup = new WebView(context);
webview_popup.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
layout.addView(webview_popup);
dialoglayout.addView(layout);
// 다이얼로그가 사용할 윈도우 크기
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);// 다이얼로그 배경 투명 on/off
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.setCanceledOnTouchOutside(true);// 다이얼로그 배경지정
// 배경 값 : http://sjava.net/2014/10/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C%EC%97%90%EC%84%9C-%EC%83%89%EC%97%90%EC%84%9C-%EC%95%8C%ED%8C%8Calpha%EA%B0%92-%EC%82%AC%EC%9A%A9/
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#BF000000")));
dialog.setContentView(dialoglayout);// 다이얼로그 애니메이션 제거
dialog.getWindow().getAttributes().windowAnimations = R.anim.anim_null;
dialog.show();
// dialog_busCitySelect.getWindow().getAttributes().windowAnimations = R.anim.anim_null;
// 사용할 윈도우 크기 최대 값으로 지정
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = display.getWidth(); //WindowManager.LayoutParams.MATCH_PARENT;
lp.height = display.getHeight(); //WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
}
외곽 : boxline
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff"/>
<stroke android:width="1px" android:color="#ffaeaeae" />
<padding android:left="1px" android:top="1px"
android:right="1px" android:bottom="1px" />
</shape>
애니메이션 : anim_null
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromYDelta="0"
android:fromXDelta="0"
android:duration="150" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="1.0"
android:duration="150"/>
</set>
응용
public void showSelectDialog() {//레이아웃 가져다 씀
display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
LinearLayout layout = new LinearLayout(context);
final Dialog dialog = new Dialog(context);
LinearLayout.LayoutParams dialogParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// dialogParams.width = display.getWidth() * 90 / 100;
// dialogParams.height = display.getHeight() * 90 / 100;
LinearLayout dialoglayout = new LinearLayout(context);
dialoglayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
dialoglayout.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
layout.setLayoutParams(dialogParams);
layout.setBackgroundResource(R.drawable.boxline);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setAnimation(null);
LinearLayout layout_btnparent = new LinearLayout(context);
layout_btnparent.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
layout_btnparent.setOrientation(LinearLayout.VERTICAL);
layout_btnparent.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
LinearLayout.LayoutParams buttonParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams imageParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams childLayoutParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1);
Button btn_select = new Button(this);
btn_select.setText("선택");
btn_select.setBackgroundColor(Color.WHITE);
LinearLayout layout_item_parent = new LinearLayout(this);
layout_item_parent.setLayoutParams(childLayoutParam);
layout_item_parent.addView(btn_select);
layout_btnparent.addView(layout_item_parent);
String[] fruit = {"apple", "banana", "pineapple", "melon", "cherry"};
for (int i = 0; i < 5; i++) {
layout_item_parent = new LinearLayout(this);
layout_item_parent.setLayoutParams(childLayoutParam);
layout_item_parent.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout layout_btn = new LinearLayout(this);
layout_btn.setLayoutParams(buttonParam);
LinearLayout layout_btn_childlayout = new LinearLayout(this);
Button btn_fruit = new Button(this);
btn_fruit.setBackgroundColor(Color.WHITE);
btn_fruit.setText(fruit[i]);
btn_fruit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
layout_btn_childlayout.addView(btn_fruit);
layout_btn.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
layout_btn.addView(layout_btn_childlayout);
LinearLayout layout_img = new LinearLayout(this);
layout_img.setLayoutParams(imageParam);
LinearLayout layout_img_childlayout = new LinearLayout(this);
ImageView img_check = new ImageView(this);
img_check.setClickable(false);
img_check.setBackgroundResource(R.drawable.ic_launcher);
layout_img_childlayout.addView(img_check);
layout_img.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
layout_img.addView(layout_img_childlayout);
layout_item_parent.setLayoutParams(childLayoutParam);
layout_item_parent.setBackgroundResource(R.drawable.topline);
layout_item_parent.addView(layout_btn);
layout_item_parent.addView(layout_img);
layout_btnparent.addView(layout_item_parent);
}
layout.addView(layout_btnparent);
dialoglayout.addView(layout);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setContentView(dialoglayout);
// dialog_busCitySelect.getWindow().getAttributes().windowAnimations = R.anim.anim_null;
/*
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
*/
dialog.show();
}