Clear Edit Text - adb

How to clear focused text editing using shell command.

I tried

adb shell input keyevent KEYCODE_CLEAR // Not worked 
adb shell input keyevent KEYCODE_DEL // Delete only one char
adb shell input keyevent KEYCODE_FORWARD_DEL // Not worked

With this, I can only delete only one character, is there any way to remove / clear focused editing text.

+4
source share
4 answers

This works for me:

function android_clear_input {
    adb shell input keyevent KEYCODE_MOVE_END

    for i in $(seq 50); do
        adb shell input keyevent KEYCODE_DEL
    done
}

Then:

android_clear_input
+4
source

If you use uiautomator ( https://github.com/xiaocong/uiautomator ), you can do this:

  • tap the EditText widget to get focus, then

  • use device(focused=True).clear_text()to clear the view, or device(focused=True).set_text("new text")to set new text.

+1
source

, , - input swipe x y x y duration . EditText. , , .

, adb shell input keyevent KEYCODE_CLEAR . , - , .

0

, , :

        mEditText.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (KeyEvent.KEYCODE_CLEAR == keyCode) {
                    mEditText.setText("");
                }
                return true;
            }
        });
0

Source: https://habr.com/ru/post/1606211/


All Articles