Android:如何使键盘始终可见?
在android中,我们如何使设备键盘在应用程序中始终可见?顶部部分显示应用程序想要呈现的内容,底部部分始终显示键盘。
In android, how do we make the device keypad always visible in the application? The top portion displays the content the application wants to render and bottom portion displays the keypad always.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 android:windowSoftInputMode="stateAlwaysVisible" 添加到 AndroidManifest.xml 文件中的活动中:
在我的测试应用程序中,这会在应用程序启动时显示键盘,尽管它没有固定在那里,但可以通过按后退按钮将其关闭。
为了确保键盘始终可见,您可能必须创建自己的键盘作为应用程序 UI 的一部分。以下教程向您展示如何使用 KeyboardView 执行此操作: http://www .fampennings.nl/maarten/android/09keyboard/index.htm
Add android:windowSoftInputMode="stateAlwaysVisible" to your activity in the AndroidManifest.xml file:
In my test app this shows the keyboard on starting of the application although it isn't fixed there but can be dismissed by pressing the back button.
To make sure the keyboard is always visible you might have to create your own keyboard as part of the UI of your application. Here is a tutorial to show you how to do this with KeyboardView: http://www.fampennings.nl/maarten/android/09keyboard/index.htm
您的布局中必须有一个
EditText
,并且需要扩展EditText
基类。然后重写onKeyPreIme()
方法,并返回True。现在您的键盘将始终可见,并且无法通过后退键关闭。警告:由于您的
onKeyPreIme()
方法返回true
,因此您无法使用后退键退出应用。示例:
onKeyPreIme() - Android 开发者
You must have an
EditText
in your layout and that need to extentEditText
base class. then OverrideonKeyPreIme()
method, and return True. Now your keyboard will be always visible and can't be dismissed by Back key.Caution: Because of your
onKeyPreIme()
method returnstrue
you can't exit your app using back key.Example:
onKeyPreIme() - Android developer
我找到了一种方法,可以在编辑
EditText
类的myEditText
字段后保持软键盘可见。诀窍是重写onEditorAction
方法,使其返回true
,否则只有在
onEditorAction
之后才返回true
“完成”键单击 (IME_ACTION_DONE
< /a>) 否则false
(另请参阅
onEditorAction
上的此答案方法)将
android:windowSoftInputMode="stateAlwaysVisible
添加到 Manifest 文件有助于在 Activity 启动时显示软键盘,但并不能阻止软键盘在每次单击“Done”键后再次消失。编辑。I found a way that works for me to keep the soft keyboard visible after an edit in my
myEditText
field of classEditText
. The trick is to override theonEditorAction
method so that it returnstrue
or else have
onEditorAction
returntrue
only after the "Done" key-click (IME_ACTION_DONE
) otherwisefalse
(see also this answer on the
onEditorAction
method)Adding
android:windowSoftInputMode="stateAlwaysVisible
to the Manifest file helped to have the soft keyboard shown at activity start but it didn't prevent it from disappearing again whenever the "Done" key was clicked after an edit.