Android Edittext question, replace keypad enter with done

后端 未结 5 708
北恋
北恋 2020-12-10 17:30

I\'m defining an edit text like so...



        
相关标签:
5条回答
  • 2020-12-10 17:58

    Here is an updated answer:

    android:maxLines="1"
    

    The accepted answer of android:singleLine="true" has been deprecated.

    0 讨论(0)
  • 2020-12-10 17:59

    Simple solution: add android:singleLine="true" for the EditText. This will replace the enter with Next (for all edittexts except the last one) and Done (for the last one).

    0 讨论(0)
  • 2020-12-10 17:59
    android:imeOptions="actionNext"
    

    It replaces the name of the enter key with "Next" in the virtual keyboard and by clicking on it - focus jumps to the next field

    In your layout, you would do things like this

    <EditText
        ...
        android:text="Field 1"
        android:imeOptions="actionNext" />
    <EditText
        ...
        android:text="Field 2"
        android:imeOptions="actionNext" />
    

    And in Java

    TextView field2 = (TextView) field1.focusSearch(View.FOCUS_RIGHT);
    field2.requestFocus();
    

    It's up to you to decide which field will request focus next.

    0 讨论(0)
  • 2020-12-10 17:59

    About your other question, getting the text to auto-erase, you should include it in android:hint instead of android:text.

    0 讨论(0)
  • 2020-12-10 18:05

    Just add in the EditText XML : android:imeOptions="actionDone"

    0 讨论(0)
提交回复
热议问题