I have a editTextbox as below and need to set cursor in the middle of it.
<EditText
android:id="@+id/editText"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textCursorDrawable="@drawable/my_custom_cursor"
android:hint="Hello My World"/>
I tried:
editText = (EditText) findViewById(R.id.editText);
int length = editText.getHint().length();
editText.setSelection(length/2); <-- problem
The length returns 0 since there is no real text exist in the editText box. Could anyone tell me how I can set initial cursor locate at the middle of "Hello My World" ?
Thanks advance!