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

Android keyboard next button issue on EditText(EditText上的Android键盘下一个按钮问题)

本文介绍了EditText上的Android键盘下一个按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am facing an issue, I have username & password fields on activity, now when I click on username keyboard appears but no next button on it and I cannot move to next Edittext control through keyboard in this case, keyboard displays enter button in it as attached in screenshot which increases its height,

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

Can anyone guide me what is the solution to this problem (to display next button on edittext)?

我的代码

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

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

推荐答案

将此行添加到您提供的代码行下方:

add this lines below your lines of code you provided:

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上的Android键盘下一个按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:EditText上的Android键盘下一个按钮问题

基础教程推荐