Android Edittext displays the cursor and obtains the focus of the Focus listener.
Android Edittext displays the cursor and obtains the focus of the Focus listener.
Edittext java code control get focus
EditText mEditText = (EditText) findViewById(R.id.et); mEditText.setFocusable(true); mEditText.setFocusableInTouchMode(true);
Show cursor
MEditText. requestFocus (); // obtain the focus cursor
No focus
mEditText.clearFocus();
Listen to EditText focus changes. when the focus is obtained, hasFocus is true.
MEditText. setOnFocusChangeListener (new android. view. view. onFocusChangeListener () {@ Override public void onFocusChange (View v, boolean hasFocus) {if (hasFocus) {// get focus} else {// lose focus }}});
Code for controlling the cursor using the XML configuration file
CursorVisible
True is displayed
False indicates hiding the cursor.
android:cursorVisible=true android:cursorVisible=false
If EditText does not automatically obtain the focus, it is set on the parent control of EditText.
android:focusable=true android:focusableInTouchMode=true
Set the cursor color in EditText
android:textCursorDrawable=#ff2244
If you want to set the same color as the font, set @ null.
// Please wait until then // zookeeper // zookeeper without any bugs! // Zookeeper has been completed before // zookeeper has been executed before being executed ┛ ┗ ┻ ┛