Skip to content
Advertisement

Python: how do I can use android.show_keyboard for my android app?

I wrote a small pygame app that fills random colors on the device’s screen:

JavaScript

But there are no UI elements (like in kivy) (but I can draw them), so I want to show/hide the keyboard from code. But I can’t find docs about android.show_keyboard and android.hide_keyboard

My attempts:

  1. When I call android.show_keyboard(), I get an error saying that 2 args are required
  2. When I add random args: android.show_keyboard(True, True), I also get an error saying that var input_type_ is not global
  3. When I change the 2nd arg to a string: android.show_keyboard(True, 'text'), the app just crashes without saving the error to file.

Can someone help me with how I can show/hide the keyboard?

Advertisement

Answer

As specified in the Python for Android documentation, android is a Cython module “used for Android API interaction with Kivy’s old interface, but is now mostly replaced by Pyjnius.”

Therefore, the solution I have found is based on Pyjnius, and essentially consists in replicating the Java code used to hide and show keyboard on Android (I used this answer as a base, but there might be something better out there), by exploiting the Pyjnius autoclass-based syntax:

JavaScript

If you want to learn more about how Pyjinius’s autoclass works, take a look at the section related to Automatic Recursive Inspection, within the Python for Android documentation.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement