【问题标题】:android:digits not allowing next button in keypadandroid:数字不允许键盘中的下一个按钮
【发布时间】:2013-10-25 11:24:04
【问题描述】:

我正在使用

android:digits="abcdefghijklmnopqrstuvwxyz. " 

当我在键盘上按回车键时,在同一屏幕上多了一个EditText,焦点不会改变。

假设我删除了

 android:digits

回车按钮工作正常并移至下一个编辑文本。

【问题讨论】:

    标签: android android-keypad


    【解决方案1】:

    在 xml 中的 EditText 中添加 android:imeOptions="actionNext"

    <EditText
            android:id="@+id/et_count"
            android:layout_width="100dp"
            android:singleLine="true"
            android:imeOptions="actionNext"
            android:layout_height="wrap_content" />
    

    【讨论】:

    • 这里不工作。当 digits 属性存在时,imeOptions 不起作用。为什么会这样?
    • @BugsHappen 要修复尝试添加 android:singleLine="true",引用自 stackoverflow.com/questions/11048007/…
    • 请添加 singleLine true 以回答不仅仅是在 cmets 中。它解决了数字问题。
    • 我可以确认 android:singleLine="true" 在 2018 年修复它。android:imeOptions="actionNext" 没有。
    【解决方案2】:

    您可以在xml 中使用可用于EditTextimeOptions 属性。

    试试下面的。它在我的情况下有效。

    XML中:

     <EditText
          android:id="@+id/edit_text1"
          android:layout_width="match_parent"
          android:layout_height="45dp"
          android:digits="abcdefghijklmnopqrstuvwxyz. " 
          android:imeOptions="actionNext"/>
    
    <EditText
          android:id="@+id/edit_text2"
          android:layout_width="match_parent"
          android:layout_height="45dp"/>
    

    然后,在 JAVA 中:

        EditText edit_text1 = (EditText) findViewById (R.id.edit_text1);
    
        EditText edit_text2 = (EditText) findViewById (R.id.edit_text2);
    
        edit_text1.setOnEditorActionListener(new OnEditorActionListener() {     
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    
                boolean handled = false;
    
                if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    edit_text2.requestFocus();
                    handled = true;
                }
    
                return handled;
           }
       });
    

    【讨论】:

      【解决方案3】:

      您必须删除 'android:digits' 才能激活 'android:imeOptions="actionNext"' 代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-03
        • 1970-01-01
        • 1970-01-01
        • 2012-05-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多