简体   繁体   中英

Android how to clear focus of edit text on closing keyboard

I am trying to do two diffrent animate on gaining focus and on keyboard go down. I am trying to detect focus with this

        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) animateUp();
            else animateDown();
        }
    });

The problem is when keyboard is closed edit text is still being focused and it cant animate the second one. How can I clear the focus after keyboard closed ?

use

  setCursorVisible(boolean) 

or use xml property for edittext

android:cursorVisible 

to remove focus when keyboard is hidden

or use imeOptions

android:imeOptions="actionGo"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM