Closed T-Dynamos closed 1 year ago
@T-Dynamos your keyboard needs to be in view before it gets its height
@kengoon Not working can you send minimal working code with kivy?
+1 not working here also.
def keyboard_height():
try:
decor_view = activity.getWindow().getDecorView()
height = activity.getWindowManager().getDefaultDisplay().getHeight()
decor_view.getWindowVisibleDisplayFrame(Rect)
return height - Rect().bottom
except JavaException:
return 0
Trashing errors is probably not a good things. Specially here, activity has no getWindow method.
I now use android module
import android
print(android.get_keyboard_height())
Hi @yunus-ceyhan, thanks for fixing this issue. But I have a small problem, I still see zero in keyboard_height() even after forceful keyboard creation within TextInput:
def create_keyboard(self, *args):
self.show_keyboard()
from kvdroid.tools import keyboard_height
print(str(keyboard_height())
Maybe I installed the new version incorrectly? I pip-installed it first from .zip:
pip install https://github.com/kvdroid/Kvdroid/archive/refs/heads/master.zip
Then I added the same zip to the Buildozer spec file:
requirements = python3, kivy, plyer, jnius, https://github.com/kvdroid/Kvdroid/archive/refs/heads/master.zip
I also did buildozer android update
.
Can you please tell me what I'm missing here and how to make the bugfix work?
@antorix Is Pydroid app installed on your Android device? If not please download it from the Play store. Instead of building your app every time we can test a simple example on Pydroid to see if it works or not.
Also you should call keyboard_height after keyboard appeared on your device otherwise it will always return 0
@yunus-ceyhan
@antorix Is Pydroid app installed on your Android device? If not please download it from the Play store. Instead of building your app every time we can test a simple example on Pydroid to see if it works or not.
I had some experience with Pydroid, but currently I work with Kivy. If you explain to me how to use Pydroid with Kvdroid, I will be glad to help. I didn't even know it supports third-party modules.
Also you should call keyboard_height after keyboard appeared on your device otherwise it will always return 0
It's exactly this way.
Install Pydroid, open the side menu, click on terminal then;
pip install https://github.com/kvdroid/Kvdroid/archive/refs/heads/master.zip
Then test the code below.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
Builder.load_string("""
#:import keyboard_height kvdroid.tools.keyboard_height
<Main>:
orientation: 'vertical'
Label:
id: lb
text: f' Keyboard height: {keyboard_height()}'
size_hint_y: None
height: dp(70)
TextInput:
text: 'When you type here keyboard height should appear'
on_text: lb.text = f' Keyboard height: {keyboard_height()}'
""")
class Main(BoxLayout):
pass
class MyApp(App):
def build(self):
return Main()
if __name__ == '__main__':
MyApp().run()
ok, it works, thanks again
Code to reproduce error
Returns 0