Forum Archive

Hide keyboard

Webmaster4o

If the user clicks into a textfield, how can I force them out of it? A user edits a textfield, then presses a button, which should close the keyboard and take the cursor focus from the textfield.

Cook92

I also would like to know how to do this. After entering text into a text field, pressing "done" or "enter" ...how to hide the keyboard?

ccc

Calling .end_editing() on your text field should do the trick.

# coding: utf-8
import time, ui

@ui.in_background
def show_hide_keyboard(text_view, sleep_secs=1):
    text_view.begin_editing()
    time.sleep(sleep_secs)
    text_view.end_editing()
    time.sleep(sleep_secs)

text_view = ui.TextView()
text_view.text = str(dir(text_view))
text_view.font = ('<system-bold>', 20)
text_view.present()
for i in xrange(10):
    show_hide_keyboard(text_view)
Cook92

Yeah that did it! Thanks!

Webmaster4o

Thanks!