我在ListView中有一些EditText字段.当我点击其中一个EditText字段时,键盘会滑入视图(应该如此),但我点击的EditText字段会失去焦点.我已经尝试使用各种InputMethodManager方法使键盘在视图中启动(为了解决问题而不是真正解决它),但这不起作用 - 当Activity出现时键盘不在视图中.
EditText的类型是number,当键盘滑入时,它是一个数字键盘,但当它完成滑动并且EditText失去焦点时,它会变为字母键盘(这强化了EditText不再具有焦点的想法).
我的问题是这些:
1)如何选择我的EditText字段并随后滑入软键盘而不会使我的EditText失去焦点?
......失败了......
2)如何使键盘在视图中开始,以便它不必滑入(从而避免我发现这样令人反感的行为)?
我的清单包括android:windowSoftInputMode="stateAlwaysVisible",但直到我点击EditText键盘才出现.忽略'stateAlwaysVisible'属性似乎只出现在模拟器中 - 在我的配置设备上,它很荣幸,因此上面的问题2可以在设备上工作......但不在模拟器中.
感谢您的任何帮助,您可以提供!
当用户按下软键盘上的"完成"时,键盘将关闭.我希望它只有在某个条件为真时才关闭(例如,密码输入正确).
这是我的代码(为按下"完成"按钮时设置一个监听器):
final EditText et = (EditText)findViewById(R.id.et);
et.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId==EditorInfo.IME_ACTION_DONE)
{
if (et.getText().toString().equals(password)) // they entered correct
{
// log them in
}
else
{
// bring up the keyboard
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Toast.makeText(Main.this, "Incorrect.", Toast.LENGTH_SHORT).show();
}
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
我意识到这不起作用的原因可能是因为它在实际关闭软键盘之前运行此代码,但这就是我需要帮助的原因.我不知道另一种方式.
可能的答案主题可能是:
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
Run Code Online (Sandbox Code Playgroud)
那种事,但我不确定.
解:
EditText et = (EditText)findViewById(R.id.et);
et.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{ …Run Code Online (Sandbox Code Playgroud) 我android:windowSoftInputMode="stateAlwaysVisible"在AndroidManifest.xml中添加了我的Activity ,这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/EditText01" android:layout_width="wrap_content"
android:layout_height="wrap_content"></EditText>
<EditText android:id="@+id/EditText02" android:layout_width="wrap_content"
android:layout_height="wrap_content"></EditText>
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Send"></Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
alt text http://img227.imageshack.us/img227/2006/18021414.png
当Activity启动时,EditText会聚焦,但不会显示软键盘.如果我点击EditText,那么我会看到软键盘.我的Activity启动时是否需要设置aditional参数以显示软键盘?
谢谢
我一直在努力让键盘保持打开状态。我不希望后退按钮隐藏它。我不想隐藏任何东西。
我已经在清单中转储了 android:windowSoftInputMode="stateAlwaysVisible",尽管构建此功能的团队似乎应该在谷歌上搜索“始终”的定义
当我按下应用程序上的后退按钮时,它会隐藏键盘。
有没有办法捕捉并杀死第一个后退按钮点击,或者将其传递给活动而不隐藏键盘?
编辑
public boolean onKeyLongPress(int keyCode, KeyEvent event){
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event){
public boolean onKeyUp(int keyCode, KeyEvent event){
public boolean onKeyDown(int keyCode, KeyEvent event) {
public void onBackPressed() {
Run Code Online (Sandbox Code Playgroud) 我正在努力解决这个问题.我正在构建我的第一个Hello World!android(cordova)应用程序,需要键盘始终显示并避免隐藏它,就像用户单击后退按钮或任何其他输入时一样.
为什么?基本上我的HTML中没有任何输入元素来触发焦点并显示键盘,它是用户执行某些命令的"终端模拟器".
键盘根本没有显示所以我去了,我添加了以下内容:
安装了Ionic Keyboard插件
cordova plugin add https://github.com/driftyco/ionic-plugins-keyboard.git
Run Code Online (Sandbox Code Playgroud)
添加了config.xml的权限
<feature name="Keyboard">
<param name="android-package" value="com.ionic.keyboard.IonicKeyboard" />
<param name="onload" value="true" />
</feature>
Run Code Online (Sandbox Code Playgroud)
在我的App模块中,以下行:
var myApp = angular.module('myApp', ['ionic']);
myApp.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
window.cordova.plugins.Keyboard.show(); // Show Keyboard on startup
// and here Trigger a show keyboard when hidden
window.addEventListener('native.hidekeyboard', keyboardHideHandler);
function keyboardHideHandler(e){
window.cordova.plugins.Keyboard.show();
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
现在,上面的实现工作,但我不认为这样处理它是优雅的,我不喜欢键盘关闭然后再次弹出的感觉.
希望我走在正确的轨道上.任何提示都将受到赞赏.
谢谢
截图

我想知道 2 件事
如何始终显示软键盘并且不让它关闭(即使按下后退或确定按钮)?
我怎样才能从中获得输入?
我已经尝试过这段代码:
EditText yourEditText= (EditText) findViewById(R.id.ed);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
Run Code Online (Sandbox Code Playgroud)
具有这些变体:
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);keyboard android android-keypad android-edittext window-soft-input-mode