按下按钮时清除编辑文本焦点并隐藏键盘

问题描述 投票:5回答:4

我正在制作带有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的关注消失,但我似乎做不到。我...

java android eclipse focus android-edittext
4个回答
12
投票

另一个解决方案是,创建虚拟布局


14
投票

要隐藏键盘,请致电:


1
投票
InputMethodManager inputManager = (InputMethodManager)
                                  getSystemService(Context.INPUT_METHOD_SERVICE); 

inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                                     InputMethodManager.HIDE_NOT_ALWAYS);
editText.setText("");

0
投票

首先您必须禁用键盘:

© www.soinside.com 2019 - 2024. All rights reserved.