활동이 시작될 때 소프트 키보드를 숨기는 방법 텍스트가 있습니다. 이제 활동을 시작할

android:windowSoftInputMode="stateVisible"매니페스트에 편집 텍스트가 있습니다. 이제 활동을 시작할 때 키보드가 표시됩니다. 숨기는 방법? android:windowSoftInputMode="stateHidden키보드가 표시되면 앱을 최소화하고 다시 시작하여 키보드가 표시되므로 사용할 수 없습니다 . 나는 함께 노력했다

InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

그러나 작동하지 않았습니다.



답변

xml을 사용하지 않으려면 키보드를 숨기기 위해 Kotlin Extension을 만드십시오.

// In onResume, call this
myView.hideKeyboard()

fun View.hideKeyboard() {
    val inputMethodManager = context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
    inputMethodManager.hideSoftInputFromWindow(windowToken, 0)
}

사용 사례에 따른 대안 :

fun Fragment.hideKeyboard() {
    view?.let { activity?.hideKeyboard(it) }
}

fun Activity.hideKeyboard() {
    // Calls Context.hideKeyboard
    hideKeyboard(currentFocus ?: View(this))
}

fun Context.hideKeyboard(view: View) {
    view.hideKeyboard()
}

소프트 키보드 를 표시 하는 방법

fun Context.showKeyboard() { // Or View.showKeyboard()
    val inputMethodManager = context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
    inputMethodManager.toggleSoftInput(SHOW_FORCED, HIDE_IMPLICIT_ONLY)
}

편집 텍스트에 대한 포커스를 동시에 요청할 때 간단한 방법

myEdittext.focus()

fun View.focus() {
    requestFocus()
    showKeyboard()
}

보너스 단순화 :

다음을 사용하기위한 요구 사항 제거 getSystemService: Splitties Library

// Simplifies above solution to just
inputMethodManager.hideSoftInputFromWindow(windowToken, 0)

답변

에서 AndroidManifest.xml:

<activity android:name="com.your.package.ActivityName"
          android:windowSoftInputMode="stateHidden"  />

또는 시도

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)‌​;

확인하시기 바랍니다


답변

키보드를 표시하거나 숨기려면 다음 기능을 사용하십시오.

/**
 * Hides the soft keyboard
 */
public void hideSoftKeyboard() {
    if(getCurrentFocus()!=null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

/**
 * Shows the soft keyboard
 */
public void showSoftKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    view.requestFocus();
    inputMethodManager.showSoftInput(view, 0);
}

답변

editText의 상위 뷰에 두 개의 속성을 추가하십시오.

android:focusable="true"
android:focusableInTouchMode="true"

답변

이것을 액티비티 태그 안의 매니페스트에 넣으십시오.

  android:windowSoftInputMode="stateHidden"  

답변

이 시도:

<activity
    ...
    android:windowSoftInputMode="stateHidden|adjustResize"
    ...
>

자세한 내용 은 이것을 보십시오 .


답변

새로운 활동 시작 또는시의 softkeyboard 숨기려면 onCreate(), onStart()당신이 아래의 코드를 사용할 수있는 등 :

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);