活动开始时如何隐藏软键盘

我android:windowSoftInputMode="stateVisible"在清单中有一个Edittext 。现在,当我开始活动时,将显示键盘。怎么藏起来?我无法使用,android:windowSoftInputMode="stateHidden因为当键盘可见时,请最小化应用程序并恢复运行,键盘应可见。我尝试过


InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);


但它没有用。


HUH函数
浏览 430回答 3
3回答

慕慕森

使用以下功能来显示/隐藏键盘:/** * 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);}

HUWWW

在AndroidManifest.xml:<activity android:name="com.your.package.ActivityName"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:windowSoftInputMode="stateHidden"&nbsp; />或尝试getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)‌;请也检查一下
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android