Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edittext cursor still blinks after closing the soft keyboard

Tags:

android

Is an edittext cursor supposed to continue blinking after the soft keyboard is closed or is this a result of testing on an emulator and wouldn't happen on an actual device? -- as pointed out by the second post in this discussion

Update:

I know that the edittexts still have the cursor blinking because they're still in focus -- logged a message whenever edittext lost focus, but message was never logged when soft keyboard closed.

Update:

I've tried doing:

@Override
public void onBackPressed() {
    super.onBackPressed();
    getCurrentFocus().clearFocus();
}

So that every time the keyboard is closed, the EditText currently in focus loses that focus and onFocusChanged() is called. The problem is that onBackPressed() isn't called when the back button is pressed when the keyboard is up. I know this because I put a toast in onBackPressed(), and no toast shows when the back button is pressed whilst the keyboard is up.

like image 400
the beest Avatar asked Sep 01 '16 01:09

the beest


People also ask

Why is my cursor blinking and not moving?

This issue happens when the blink rate of the cursor is set to the least value or 0. You may refer to these steps to reset this setting. a) Press “Windows Logo” + “X” keys on the keyboard and choose “Control Panel” from that menu. b) In the “Control Panel” window, open the keyboard settings by clicking on the “Keyboard” icon.

How do I fix the text cursor indicator on my screen?

To work around that, simply turn off and turn on the Use text cursor indicator setting again. Occasionally, you might see that the text cursor indicator stay on the screen or reappear after the app has been closed or the page contents have scrolled away.

How do I change the blink rate of my cursor?

b) In the “Control Panel” window, open the keyboard settings by clicking on the “Keyboard” icon. c) Normally, on the “Speed” tab, (the name of the tab may vary), check if you have any settings to increase or decrease the cursor blink rate.

Do you have trouble finding the text cursor in the middle?

Have you ever had an issue finding the text cursor in the middle of a large amount of text, during a presentation, or on the screen in an educational setting? Starting with Windows 10 build 18945, the new Text cursor indicator (when turned on) will help you see and find the text cursor wherever you are at any time.


2 Answers

First create a custom Edit text. Below is the example which has a call back when keyboard back is pressed to dismiss the keyboard

public class EdittextListner extends EditText {

private KeyImeChange keyImeChangeListener;

public EdittextListner(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void setKeyImeChangeListener(KeyImeChange listener) {
    keyImeChangeListener = listener;
}

public interface KeyImeChange {
    public boolean onKeyIme(int keyCode, KeyEvent event);
}

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyImeChangeListener != null) {
        return keyImeChangeListener.onKeyIme(keyCode, event);
    }
    return false;
}

}

Secondly change your EditText to EdittextListner in you layout file.

Finally do the following

 mLastNameEditText.setKeyImeChangeListener(new EdittextListner.KeyImeChange() {
        @Override
        public boolean onKeyIme(int keyCode, KeyEvent event) {
            mLastNameEditText.clearFocus();
            return true;
        }
    });

This worked for me. Hope this helps

like image 97
Avinash4551 Avatar answered Oct 19 '22 09:10

Avinash4551


Edittext is a View which accept input from user, so it is not related with keyborad open or close, when user will click on edittext, that edittext will get focus and cursor will start to blink for taking input,

So you can do one thing as when you are closing keyboard at the same time you can also set visibility of cursor for that edittext so it will stop to blink,

For that you need to write below line when you hide keyboard.

    editTextObject.setCursorVisible(false);

This will stope cursor to blink.

like image 21
Vickyexpert Avatar answered Oct 19 '22 09:10

Vickyexpert