Android Soft keyboard action button

我们两清 提交于 2019-11-27 14:20:56

问题


My layout has 4 EditText views and a submit Button view. I need to have "Next" button for the first 3 EditText's and a "Done" button for 4th EditText field in place of a "New Line" key of soft keyboard.

How can this be done?


回答1:


In your layout, just set the XML attributes android:imeOptions="actionNext" for your first three text boxes and android:imeOptions="actionDone" for the last one.

See: android:imeOptions documentation

Also, there's a small XML example in the training docs.




回答2:


to navigate the focus to the next edit field add

android:imeOptions="flagNavigateNext"

and for dismissing the softkey with done click add

android:imeOptions="actionDone"

on your layout :)




回答3:


Add android:singleLine="true" in your button xml




回答4:


I think what you're looking for is something like this:

EditText nextText = new EditText(this)
{
    @Override
    public InputConnection onCreateInputConnection(final EditorInfo outAttrs)
    {
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
        return (super.onCreateInputConnection(outAttrs));
    }
};

EditText doneText = new EditText(this)
{
    @Override
    public InputConnection onCreateInputConnection(final EditorInfo outAttrs)
    {
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
        return (super.onCreateInputConnection(outAttrs));
    }
};

It first one will take the user to the next field in the layout that accepts text. The second will close the IME (the soft keyboard).



来源:https://stackoverflow.com/questions/6007204/android-soft-keyboard-action-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!