【问题标题】:Android keyboard next button issue on EditTextEditText上的Android键盘下一个按钮问题
【发布时间】:2012-01-25 13:03:03
【问题描述】:

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

谁能指导我解决这个问题的方法(在edittext上显示下一个按钮)?

我的代码

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

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

【问题讨论】:

    标签: android android-edittext


    【解决方案1】:

    在您的 xml 中添加 android:singleLine="true" android:nextFocusDown="@+id/textView2"。 将显示 Next 键并同时聚焦到下一个字段。

    【讨论】:

    • 这对我有用,但可能需要注意的是,如果您设置了 android:imeOptions="actionNext",那么它将覆盖此答案中提到的属性
    • 如果你使用 android:singleLine="true" 意味着它本身就足以在键盘上看到“下一步”按钮
    • 当我摆脱android:imeOptions="actionNext"时它对我有用
    【解决方案2】:

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

    More Examples

    【讨论】:

    • 我在edittext上使用过它,但我不知道为什么它不起作用。 :(
    【解决方案3】:

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

    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;
        }
    });
    

    【讨论】:

    • 感谢您的回复,它已停止增加edittext高度但我仍然无法移动到下一个editext :(
    • 请检查我编辑的答案。txtUserid 的 onKeyListener 中的行已更改。
    • 智能工作+1,但我认为这不适用于多行输入?
    • @deepakSharma:是的..但我根据他的要求提出了建议。显然这是一个技巧。
    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

      另一个最佳解决方案是:

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

      【讨论】:

      • "next" 产生错误:“错误:(48, 45) 不允许使用字符串类型(在 'imeOptions' 处,值为 'next')。”。它应该是“actionNext”。并且 android:singleLine="true" 已被弃用。改用 android:maxLines="1"。
      【解决方案6】:

      添加您的 xml 布局,

      假设你想要 4 个编辑文本,所以你在下面设置前三个编辑文本,

      android:imeOptions="actionNext"
      

      最后一个editext你设置

      android:imeOptions="actionDone"
      

      你添加行所以添加,使用

        android:singleLine="true" 
      

      【讨论】:

      • 奇怪的是 MaxLines="1" 在我的 Galaxy 4 上不起作用,必须使用 singleLine="true"
      • singleline="true" 它已被弃用但它的工作兄弟,,
      【解决方案7】:

      你需要注意几件事:

      1. 添加android:singleLine="true"
      2. 在您的 XML 中添加 android:nextFocusDown="@+id/tv2"
      3. 不要加android:imeOptions="actionNext",否则会覆盖上面两个属性。

      【讨论】:

        【解决方案8】:

        使用这个属性:

        android:inputType="textPersonName"
        

        【讨论】:

          【解决方案9】:

          添加

          android:inputType="text"

          你的edittext标签中的行。你的问题就会得到解决。

          【讨论】:

            【解决方案10】:

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

            【讨论】:

            • 已弃用。请改用android:maxLines="1"
            【解决方案11】:

            只需添加 android:singleLine="true" 你不需要那个代码

            【讨论】:

              【解决方案12】:

              android:singleLine="true" 已弃用

              使用

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

              改为

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2011-10-17
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多