我正试图在Android Studio项目中隐藏软键盘。 hideKeyboard()方法中的视图不断出现为空...我无法弄清楚为什么......请指教。
@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);
}
}
答案 0 :(得分:1)
您可以在主要节日中使用android:windowSoftInputMode="stateHidden"
隐藏活动启动时的键盘
`<activity android:name=".YourActivity"
android:windowSoftInputMode="stateHidden" />`
答案 1 :(得分:0)
更新InputMethodManager:
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
答案 2 :(得分:0)
尝试:
imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
就我而言,它有效。