我正在制作带有edittext和按钮的应用程序。当我在edittext中输入内容,然后单击一个按钮时,我希望键盘和专注于edittext的元素消失,但我似乎做不到。
我在XML中插入了这两行代码:
android:focusable="true"
android:focusableInTouchMode="true"
我也试图在按钮单击方法中添加它:
edittext.clearFocus();
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
而且当我按下按钮后,键盘仍然在那里,edittext仍然具有焦点。]
我正在制作带有edittext和按钮的应用程序。当我在edittext中输入内容,然后单击按钮时,我希望键盘和对edittext的关注消失,但我似乎做不到。我...
另一个解决方案是,创建虚拟布局
要隐藏键盘,请致电:
InputMethodManager inputManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
editText.setText("");
首先您必须禁用键盘: