How to set cursor position in EditText?

前端 未结 23 1505
广开言路
广开言路 2020-11-28 02:51

There are two EditText,while loading the page a text is set in the first EditText, So now cursor will be in the starting place of EditText, I want

23条回答
  •  温柔的废话
    2020-11-28 03:26

    You can use like this:

    if (your_edittext.getText().length() > 0 ) {
    
        your_edittext.setSelection(your_edittext.getText().length());
    }
    

    Can you add this line to your EditText xml

    android:gravity="right"
    android:ellipsize="end"
    android:paddingLeft="10dp"//you set this as you need
    

    But when any Text writing you should set the paddingleft to zero

    you should use this on addTextChangedListener

提交回复
热议问题