在Android应用上隐藏键盘
当我触摸textedit时,键盘android会打开。在Android应用上隐藏键盘
我想停止。
我的代码:
activity_main.xml中
<EditText
android:id="@+id/edit_box"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:focusable="true"
android:background="#ffffff">
</EditText>
Main.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
caixa = (EditText)findViewById(R.id.edit_box);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(caixa.getWindowToken(),InputMethodManager.RESULT_UNCHANGED_SHOWN);
可以隐藏在清单中的键盘:
<activity
...
android:windowSoftInputMode="stateHidden" >
</activity>
不行...键盘继续开放 我的活动: [代码] 2014-10-30 00:13:32
试试这个:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(caixa.getWindowToken(), 0);
我把这段代码放在onCreate方法的main.java中? – 2014-10-30 10:36:27
如果你不希望的EditText试试这个..
protected void showKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (activity.getCurrentFocus() == null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
} else {
View view = activity.getCurrentFocus();
inputMethodManager.showSoftInput(view,InputMethodManager.SHOW_FORCED);
}
}
/**
* Hide keyboard.
*/
protected void hideKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view == null) {
if (inputMethodManager.isAcceptingText())
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
} else {
if (view instanceof EditText)
((EditText) view).setText(((EditText) view).getText().toString()); // reset edit text bug on some keyboards bug
inputMethodManager.hideSoftInputFromInputMethod(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
我把这段代码放在onCreate方法的main.java中? – 2014-10-30 10:37:10
是的......你可以放在oncreate()方法 – samsad 2014-10-30 10:39:25
再次抱歉......活动在哪里,我换成了?预期为 – 2014-10-30 10:50:34
进行编辑,你为什么不直接使用一个TextView? – Burn 2014-10-29 23:22:32
我想使用EditText有几个原因。有没有办法隐藏Android键盘? – 2014-10-29 23:48:55