【问题标题】:Change behavior of action key android with imeOptions doesnt work使用 imeOptions 更改操作键 android 的行为不起作用
【发布时间】:2015-08-13 14:48:30
【问题描述】:

我尝试从一个 TextView 元素跳转到我的 Android 活动中的下一个可编辑对象。下一个 Object 是 ListView 的一个元素,它是可编辑的。 我尝试使用 imeOptions 但它仍然在 TextEdit 对象中执行换行符。 我的 XML 如下所示:

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:hint="@string/question_hint"
            android:id="@+id/questionField"
            android:textColor="@color/text_color"
            android:textCursorDrawable="@null"
            android:maxLength="@integer/question_length"
            android:imeOptions="actionNext"/>
        <!--android:minLines="2"-->

我还在activity的oncreate方法中添加了一个codeline:

questionField = (EditText) findViewById(R.id.questionField);
questionField.setImeOptions(EditorInfo.IME_ACTION_NEXT);

但它不起作用。有人有想法吗?谢谢

【问题讨论】:

    标签: java android textedit imeoptions


    【解决方案1】:

    试试这样的:

    questionField.setOnEditorActionListener(
                new TextView.OnEditorActionListener() {
                    public boolean onEditorAction(TextView exampleView,
                            int actionId, KeyEvent event)
                    {
    
                        if ((actionId == EditorInfo.IME_ACTION_DONE
                                || actionId == EditorInfo.IME_ACTION_NEXT
                                || actionId == EditorInfo.IME_ACTION_GO
                                || (event != null
                                        && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)))
                        {
    
                            return nextView.requestFocus()  // the next view you want the focus to be on
                        }
                        else
                        {
                            return false;
                        }
                    }
                });
    

    【讨论】:

    • 嗨,它卡在 Line new TextView with
    • 仍然不起作用:(。我希望键盘的绿色输入按钮更改为“下一步”按钮版本。但它仍然是输入
    猜你喜欢
    • 2015-01-16
    • 2016-05-26
    • 1970-01-01
    • 2015-05-25
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    相关资源
    最近更新 更多