popup window로 만들고 있는데,
onkeyListener 등록이 전혀 안되네요 ㅠㅠ
다음은 코드입니다.
private PopupWindow pw;
private void GeneratePopupWindow() {
try {
LayoutInflater inflater = (LayoutInflater) Project_SNUGO.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_selection, null);
pw = new PopupWindow(layout, 360, 280, true);
Drawable Background = pw.getBackground();
pw.setOutsideTouchable(true);
pw.setBackgroundDrawable(Background);
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
Button btn_yes = (Button)layout.findViewById(R.id.Decision_Yes);
Button btn_no = (Button)layout.findViewById(R.id.Decision_No);
btn_yes.setOnClickListener(Decision_ClickListener);
btn_no.setOnClickListener(Decision_ClickListener);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
findViewById(R.id.find_by_location).setOnKeyListener(Decision_KeyListener);
}
catch (Exception e) {
e.printStackTrace();
}
}
/***********************************************************************************/
private View.OnKeyListener Decision_KeyListener = new View.OnKeyListener() {
public boolean onKey(View v, int KeyCode, KeyEvent event) {
if(event.getAction()==KeyEvent.ACTION_DOWN){
switch(KeyCode){
case KeyEvent.KEYCODE_BACK:
pw.dismiss();
return true;
}
}
return false;
}
};
/***********************************************************************************/
인터넷을 마구 뒤져보니, 팝업 윈도우에서는 KeyListener가 먹질 않는다고 해서 BackGround Touchable하게 만들고 Background에 대해서 KeyListener를 달으라고 했는데, 위에서 터쳐블 하게 만들어놔도 되지가 않네요......popupWindow가 뷰가 아니니까 리스터 등록도 안되구요....
View layout 에서 layout도 나름 View인데 이건 또 왜 등록이 안될까요....??
그리고 현재는 배경이 전혀 blur가 안되어 있는데, 배경 블러를 하는 방법을 좀 알려주시면 감사하겠습니다
반나절가량 이거만 헤집고 있는데 너무안되네요 ㅠㅠ
커스텀 팝업을 만드시는 것이라면 시루떡님 말씀대로 만드는 방법이 있고, Activity 를 하나 생성해서 팝업처럼 사용하는 방법도 있습니다.
이 경우 키 처리를 그냥 일반 Activity처럼 해주면 되니 편하겠죠. (일반 Activity와 동일합니다. 다른건 Dialog 처럼 화면에 뿌려진다는거 정도...)
그냥 보통 Activity 만드시는 것 처럼 만드셔서 호출도 startActivity(intent);하시면 되구요.
Manifest.xml 파일에서 Acticity 추가 하는 부분에 theme 값만 변경하면 됩니다.
<activity
android:name=".PopupAddFolder"
android:theme="@android:style/Theme.Dialog"
android:screenOrientation="portrait"
>
</activity>
이런식으로요...
저 Activity 의 Theme가 Dialog이기 때문에 보통의 Dialog처럼 blur처리가 됩니다.
저기서 한가지 더 처리 해 주셔야 하는 것은 popup으로 쓰실 Activity에서 requestWindowFeature(Window.FEATURE_NO_TITLE); 를 추가 해 주셔야 합니다.
안드러면 Title bar가 뜨겠죠...




팝업 사용하시려면 가장 일반적인 방법은 AlertDialog.Builder 이용하는 겁니다.
AlertDialog.Builder builder = new AlertDialog.Builder();
builder.setPositive, builder.setNegative 등으로 확인 취소버튼 구현가능하고,
builder.show() 하면 dialog 객체가 리턴됩니다. 그 dialog 객체에 onDismissListener 등록하시면
팝업이 닫힐때 호출 되고, 배경 blur 은 AlertDialog 의 기본 속성이니, 자동으로 된다고 생각하시면됩니다.