Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Android Studio项目中隐藏软键盘,为什么?_Android_View_Android Softkeyboard - Fatal编程技术网

无法在Android Studio项目中隐藏软键盘,为什么?

无法在Android Studio项目中隐藏软键盘,为什么?,android,view,android-softkeyboard,Android,View,Android Softkeyboard,我试图在Android Studio项目中隐藏软键盘。hideKeyboard方法中的视图一直显示为null。。。我不明白为什么。。。请告知 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rewashlog_options); luxuryCo

我试图在Android Studio项目中隐藏软键盘。hideKeyboard方法中的视图一直显示为null。。。我不明白为什么。。。请告知

  @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rewashlog_options);

    luxuryCountTextView = (TextView) findViewById(R.id.luxuryCountTextView);
    fullCountTextView = (TextView) findViewById(R.id.fullCountTextView);
    quickCountTextView = (TextView) findViewById(R.id.quickCountTextView);
    totalCountTextView = (TextView) findViewById(R.id.totalCountTextView);
    emailRecipient = (EditText) findViewById(R.id.emailRecipient);

    instantiateMonthSpinner();
    instantiateYearSpinner();
    getEntireRewashList();
    updateListView();
    hideKeyboard();

}

 private void hideKeyboard() {
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

}

更新您的InputMethodManager:

InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
您可以在mainfest中使用android:windowSoftInputMode=stateHidden在活动启动时隐藏键盘,如下所示

`<activity android:name=".YourActivity"
        android:windowSoftInputMode="stateHidden" />`
尝试:


在我的情况下,它可以工作。

尝试使用handler.post隐藏它。您现在正试图在显示之前将其隐藏。请尝试使用yourEditText.getWindowToken而不是view.getWindowToken。我想这是电子邮件收件人。
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);