python:如何在android应用程序中使用android.show_键盘?

rsaldnfx  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(204)

我编写了一个小的pygame应用程序,可以在屏幕上填充随机颜色:

import sys, os
andr = None # is running on android
try:
    import android
    andr = True
except ImportError:
    andr = False
try:
    import pygame
    import sys
    import random
    import time
    from pygame.locals import *
    pygame.init() 
    fps = 1 / 3  # 3 fps
    width, height = 640, 480
    screen = pygame.display.set_mode((width, height), FULLSCREEN if andr else 0) # fullscreen is required on android
    width, height = pygame.display.get_surface().get_size() # on android resolution is auto changing to screen resolution
    while True:
        screen.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
        pygame.display.flip()
        time.sleep(fps)
except Exception as e:
    open('error.txt', 'w').write(str(e)) # Save error into file (for android)

但并没有ui元素(比如kivy)(但我可以绘制它们),所以我想在代码中显示/隐藏键盘。但是我找不到关于android.show\u键盘和android.hide\u键盘的文档
我的尝试:
当我打电话的时候 android.show_keyboard() ,我得到需要2个参数的错误
添加随机参数时: android.show_keyboard(True, True) ,我得到了一个错误 input_type_ 它不是全球性的
当我将第2个参数更改为字符串时: android.show_keyboard(True, 'text') ,应用程序正在崩溃,并且没有将错误保存到文件中。
有人知道如何显示/隐藏键盘吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题