보통은 onClick 이라던지, 개발자가 원하는 순간에 Activity 에서
imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);
이 방법을 이용해서 소프트 키보드를 띄운다.
그러나, 지금 하려는 작업은 Activity 에서 특정 버튼 클릭 시 CustomDialog 를 띄우고
CustomDialog 에 속해있는 EditText 의 키보드가 특정 버튼 클릭과 동시에 나타나게
하려고 한다.
결국 사용자가 특정 버튼을 클릭할 경우, Dialog 를 제외한 화면이 어둡게 가려 지면서
EditText 의 키보드가 나타나는 것이다. Activity 에서 이렇게 할 경우 위와 같은 방법으로
하면 문제가 없지만, CustomDialog 는 Dialog 를 상속받은 Class 로 Activity 가 아니라,
동일 방법으로는 키보드가 나타나지 않는다.
public class CustomDialog extends Dialog {
Context mContext = null;
static EditText edit = null;
static InputMethodManager ime = null;
public CustomDialog(Context context, int theme) {
super(context, theme);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog, null);
edit = ((EditText) layout.findViewById(R.id.message));
ime = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
// ime.showSoftInput(edit, 0);
ime.showSoftInputFromInputMethod(edit.getWindowToken(), InputMethodManager.SHOW_FORCED);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
생성자에 이런 방법으로 구현 시 소프트 키보드가 Activity 가 아닌 곳에서도 볼 수 있다.