Keyboard questions

Hi,

I have 2 questions regarding the usage of the keyboard widget. I’m using Lvgl V6.

  1. How can I reopen the keyboard if I accidentally close it by clicking the close button? The set_hidden() doesn’t seem to work…

  2. In my screen layout, I have a couple of one-line text area at the lower half of the screen, so they get blocked and covered when the keyboard pops up. Is there a work-around? I just can’t fit all the text areas into the upper half the screen.

Thanks,
Kaiyuan

By default, the close button will delete the keyboard if there is no custom event handler set. If you do set a custom event handler, LV_EVENT_CANCEL will be sent when the keyboard close button is pressed and you can do what you wish with it.

The best solution that I’ve seen is to resize whatever container/page is holding your text areas so that the keyboard fits at the bottom. This should make the text area stay on the screen.

Thanks for the quick reply.

So, basically I need to re-create a keyboard once I closed (deleted) it, right?

Thanks for the hint for the 2nd question, I know what to do now.

Kaiyuan

I figured it out. Just leaving a note in case someone has similar questions.

  1. I set a keyboard event callback like below:
def keyboard_event_cb(event_kb, event):
    event_kb.def_event_cb(event)
    if event == lv.EVENT.CANCEL:
        kb.set_hidden(True)
        global current_input_placeholder
        # 'Set Offset' is the placeholder of the TA which is at the lower part of the screen
        # So when I close the KB, the container should be moved back to normal position
        if current_input_placeholder == 'Set Offset':
            popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)

So that when the “Close” button on the KB is clicked, the KB is set to ‘hidden’ instead of being deleted. Then for the textareas, whenever a TA is clicked, it will check whether the KB is hidden, if so, the KB hidden status will be set to ‘’‘False’’’ to look like it’s reopened.

  1. I detect whether the textareas on the lower half of the screen is clicked by getting it’s placeholder text - I have tried getting it’s label, but it didn’t work, I don’t know why, the ta.get_label() returned an lvgl obj rather than the label obj. If it’s the textarea on the lower half of the screen gets clicked, the container will be moved up to leave space for the KB.
def input_event_cb(ta, event):
    global current_input_placeholder, popup_pid
    if event == lv.EVENT.CLICKED:
        current_input_placeholder = ta.get_placeholder_text()
        # 'Set Offset' is the placeholder of the TA which is at the lower part of the screen
        # So when I click on that TA, the container should be moved up to leave space for the KB
        if current_input_placeholder == 'Set Offset':
            popup_pid.align(bg, lv.ALIGN.CENTER, 0, -55)
        else:
            popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)
        if kb.get_hidden():
            kb.set_hidden(False)
        kb.set_ta(ta)

You should be able to just resize the container whenever any text area is clicked. That should also handle the case where someone decides to click one text area and then scroll to another one.