每当我点击EditText
时出现Android键盘弹出窗口,但我不想弹出键盘。
我想永久隐藏当前应用程序的Android键盘弹出窗口。
我该怎么做?
答案 0 :(得分:27)
将标记textIsSelectable
设置为true
会禁用软键盘。
您可以在xml布局中设置它,如下所示:
<EditText
android:id="@+id/editText"
...
android:textIsSelectable="true"/>
或者以编程方式,像这样:
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
光标仍然存在,你可以select/copy/cut/paste
,但软键盘永远不会显示。
答案 1 :(得分:12)
您可以尝试使用这样的按钮伪造您的EditText:
<Button
android:id="@+id/edit_birthday"
style="@android:style/Widget.EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_birthday"/>
答案 2 :(得分:10)
在清单中:
<activity
android:name=".YourActivity"
.
.
.
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
答案 3 :(得分:5)
可以找到解决方案here:
public void onCreate(Bundle savedInstanceState) {
edittext = (EditText) findViewById(R.id.EditText01);
edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
}
答案 4 :(得分:1)
适用于所有Android版本。
在您的XML中,使用属性android:textIsSelectable="true"
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
.
.
.
android:textIsSelectable="true"/>
而且,在您的Java类中:
editText1.setShowSoftInputOnFocus(false);
在科特林:
editText1.showSoftInputOnFocus = false
答案 5 :(得分:0)
这两行应该做你想要的:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
答案 6 :(得分:0)
试试这个
public void disableSoftKeyboard(final EditText v) {
if (Build.VERSION.SDK_INT >= 11) {
v.setRawInputType(InputType.TYPE_CLASS_TEXT);
v.setTextIsSelectable(true);
} else {
v.setRawInputType(InputType.TYPE_NULL);
v.setFocusable(true);
}
}
答案 7 :(得分:0)
尝试在yout onCreate()
方法中添加此内容。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
未经测试但应该可以使用!!
答案 8 :(得分:0)
在您的xml文件中,您可以使用:
b
答案 9 :(得分:0)
在您的xml set属性中,可编辑为false。 它不会让您编辑文本,并且不会打开键盘。
<EditText
android:editable="false"
/>