当我触摸textedit时,键盘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);
答案 0 :(得分:0)
您可以在清单中隐藏键盘:
<activity
...
android:windowSoftInputMode="stateHidden" >
</activity>
答案 1 :(得分:0)
试试这个:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(caixa.getWindowToken(), 0);
答案 2 :(得分:0)
试试这个..
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);
}
}