EditText上的Android键盘下一个按钮问题

时间:2012-01-25 13:03:04

标签: android android-edittext

我正面临一个问题,我有用户名&活动上的密码字段,现在当我点击用户名键盘时出现但没有下一个按钮,在这种情况下我无法通过键盘移动到下一个Edittext控件,键盘显示在屏幕截图中输入按钮,增加其高度,

任何人都可以指导我这个问题的解决方案是什么(在edittext上显示下一个按钮)?

enter image description here

我的代码

txtUserid = (EditText)findViewById(R.id.txtUserID);
        txtUserPasword = (EditText)findViewById(R.id.txtPassword);

        txtUserid.setNextFocusDownId(R.id.txtPassword);
        txtUserPasword.setNextFocusDownId(R.id.btnLogin);

12 个答案:

答案 0 :(得分:102)

在xml上添加android:singleLine="true" android:nextFocusDown="@+id/textView2"。 将显示Next键并将焦点转移到下一个字段。

答案 1 :(得分:51)

在您的布局中,只需为前三个文本框设置XML属性android:imeOptions="actionNext",为最后一个文本框设置android:imeOptions="actionDone"

More Examples

答案 2 :(得分:35)

在您提供的代码行下方添加以下行:

txtUserid.setOnKeyListener(new OnKeyListener() {

    public boolean onKey(View v, int keyCode, KeyEvent event) {
          // If the event is a key-down event on the "enter" button
          if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
               (keyCode == KeyEvent.KEYCODE_ENTER))
          {
                // Perform action on Enter key press
                txtUserid.clearFocus();
                txtUserPasword.requestFocus();
                return true;
          }
          return false;
    }
});

txtUserPasword.setOnKeyListener(new OnKeyListener() {

    public boolean onKey(View v, int keyCode, KeyEvent event) {

          if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER))
          {
                 // Perform action on Enter key press
                 // check for username - password correctness here
                 return true;
          }
          return false;
    }
});

答案 3 :(得分:8)

如果 EditText 应该只有1行,请在XML上添加属性android:singleLine="true",这将删除Enter键并将其替换为 Next / 完成按钮。

答案 4 :(得分:7)

另一个最佳解决方案是:

android:singleLine="true" 
android:imeOptions="actionNext"

答案 5 :(得分:4)

添加你的xml布局,

假设你想要4行edittext,所以前面有三个editext u,

android:imeOptions="actionNext"

和最后一个editext u set

android:imeOptions="actionDone"

你添加行,所以添加,使用

  android:singleLine="true" 

答案 6 :(得分:2)

使用此属性:

android:inputType="textPersonName"

答案 7 :(得分:1)

只需将android:singleLine =“true”添加到布局XML中的EditText标记..

答案 8 :(得分:1)

只需添加android:singleLine =“true”您不需要该代码

答案 9 :(得分:1)

添加

android:inputType =“ text”

您的edittext标记中的

行。这样您的问题就会解决。

答案 10 :(得分:1)

您需要注意以下几点:

  1. 添加android:singleLine="true"
  2. 在您的XML上添加android:nextFocusDown="@+id/tv2"
  3. 请勿添加android:imeOptions="actionNext",否则它将覆盖以上两个属性。

答案 11 :(得分:0)

android:singleLine="true"已弃用

使用

 android:maxLines="1"
 android:inputType="text"

代替

相关问题