Android Edittext displays the cursor and obtains the focus of the Focus listener.

Source: Internet
Author: User

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 ┛ ┗ ┻ ┛

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.