2017-04-10 12 views
0

edittext가있는 상황입니다. 편집 텍스트에서 add를 누르면 목록에 구성원이 추가됩니다. 언제 (또는 아닙니다) 사용자 지정 대화 상자를 열고 있어요 추가됩니다. 같이 정의된다사용자 정의 대화 상자가 닫힌 후 Android에서 소프트 키보드 숨기기

customDialogTeamMember = new CustomDialogTeamMember(............); 
    customDialogTeamMember.makeDialog(); 
    editText.getText().clear(); 
    editText.clearFocus(); 
    hideSoftKeyboard(); 

내 hideSoftKeyboard() : 편집 텍스트에 추가 버튼을 클릭하면 내 활동에

내가이 코드를 한

public void hideSoftKeyboard() { 
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
} 

이 방법은 다른 섹션에서 작동 앱. 하지만 여기서 작동하지 않습니다!

사용자 정의 대화 상자가 열립니다. 내가 키보드를 닫으면 키보드가 화면에 계속 뜬다. 무슨 문제가 될 수 있니?!

+1

는 무시 했 다음 방법을 사용 귀하의 활동에 onDismissDialog를 호출하고 hideSoftKeyboa를 호출하십시오. rd(); 그 안에? – AlexTa

+1

참조 : - http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard – Hangman

답변

2

및 숨기기 키보드

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); 
//Hide: 
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 
//Show 
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); 




private void hideKeyboard() { 
    // Check if no view has focus: 
    View view = this.getCurrentFocus(); 
    if (view != null) { 
     InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
    } 
} 

private void showKeyboard() { 
    // Check if no view has focus: 
    View view = this.getCurrentFocus(); 
    if (view != null) { 
     InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); 
    } 
} 
0

저는 이것을 제 사례에 사용했습니다.

// for hide keyboard 
    public static void hideKeyboard(Activity activity) { 
     InputMethodManager iim = (InputMethodManager) 
       activity.getSystemService(Context.INPUT_METHOD_SERVICE); 

     if (activity.getCurrentFocus() != null) 
      iim.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 
        InputMethodManager.HIDE_NOT_ALWAYS); 
    } 

이 방법을 귀하의 요구 사항으로 부르십시오. 알려주세요. 희망이 도움이 될 것입니다. 표시하려면

0
// Check if no view has focus: 
View view = this.getCurrentFocus(); 
if (view != null) { 
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
} 

에 체크 아웃

0

숨기고 소프트 키보드를 표시하려면

private void hideKeyboard() { 
    // Check if no view has focus: 
    View view = this.getCurrentFocus(); 
    if (view != null) { 
     InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
    } 
} 

private void showKeyboard() { 
    // Check if no view has focus: 
    View view = this.getCurrentFocus(); 
    if (view != null) { 
     InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); 
    } 
} 
0
// minimize keyboard 
    try { 
     InputMethodManager imm = (InputMethodManager)activity.getSystemService(INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), 0); 
    } catch (Exception e) {}