每当我点击EditText
Android 键盘弹出窗口时出现,但我不希望键盘弹出。
我想永久隐藏当前应用程序的 android 键盘弹出窗口。
我怎样才能做到这一点?
每当我点击EditText
Android 键盘弹出窗口时出现,但我不希望键盘弹出。
我想永久隐藏当前应用程序的 android 键盘弹出窗口。
我怎样才能做到这一点?
将标志设置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
但软键盘将永远不会显示。
您可以尝试使用这样的按钮伪造您的 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"/>
在清单中:
<activity
android:name=".YourActivity"
.
.
.
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
适用于所有 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
解决方案可以在这里找到:
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;
}
});
}
尝试这个
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);
}
}
这两行应该做你想做的事:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
尝试在你的onCreate()
方法中添加这个。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
未经测试,但它应该工作!
在您的 xml 设置属性中可编辑为 false。它不会让您编辑文本,也不会打开键盘。
<EditText
android:editable="false"
/>
在您的 xml 文件中,您可以使用它:
android:editable="false"