清除的EditText重点和隐藏键盘当按钮被pressed [英] Clear edittext focus and hide keyboard when button is pressed
本文介绍了清除的EditText重点和隐藏键盘当按钮被pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用的EditText和一个按钮的应用程序。当我输入的东西进入的EditText,然后点击一个按钮,我想上的EditText键盘和焦点消失,但我似乎无法做到这一点。
I'm making an app with edittext and a button. When I enter something into edittext and then click a button, I want the keyboard and focus on edittext to disappear but I can't seem to do it.
我插入这两条线code的XML:
I inserted these 2 lines of code in XML:
android:focusable="true"
android:focusableInTouchMode="true"
我也试过在按钮单击方法补充一点:
I also tried to add this in the button click method:
edittext.clearFocus();
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
和它只是将无法正常工作,当我preSS按钮,键盘仍然是那里的EditText仍然具有焦点。
And it just won't work, after I press the button, the keyboard remains there and edittext still has focus.
推荐答案
另一种解决方案是,创建一个虚拟布局
another solution is, create a dummy layout
<!-- Dummy item for focus at startup -->
<LinearLayout
android:id="@+id/dummy_id"
android:orientation="vertical"
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
和设置重点你的 onButtonClickFunction
((LinearLayout) findViewById(R.id.dummy_id)).requestFocus();
这篇关于清除的EditText重点和隐藏键盘当按钮被pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文