Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

ScrollView cannot 'see' on-screen keyboard (height)

91 views
Skip to first unread message

Henrik R.

unread,
Nov 23, 2024, 4:16:14 PM11/23/24
to Kivy users support
I have put a BoxLayout with some Labels and 3 TextInput fields in a ScrollView.
I expected that the ScrollView could 'see' the on-screen keyboard, and thus make the content of the BoxLayout scrollable within the part of the screen that is not in use by the keyboard. But that does not work. 
Is there any way to make my ScrollView (or the whole app) only use the part of the screen that is actually visible when a TextInput field activates an on-screen keyboard on a smartphone?

berk berk

unread,
Nov 23, 2024, 6:08:36 PM11/23/24
to Kivy users support
scroll_view = ScrollView(size_hint_y=None, height = 550)

You can settings your scroll height when touch textinputs

550, 650, 750 for textinput1, 2, 3
24 Kasım 2024 Pazar tarihinde saat 00:16:14 UTC+3 itibarıyla Henrik R. şunları yazdı:

Henrik R.

unread,
Nov 23, 2024, 6:16:48 PM11/23/24
to Kivy users support
In order to set a specific height of the scrollview you need to know the height of the keyboard. Don't you?

berk berk

unread,
Nov 23, 2024, 6:29:18 PM11/23/24
to Kivy users support
Yeah, for prefect solution. Generally mobile device keyboards cover %30-50 on screen. Also i don't remember to is there specific parameter to know screen keyboard on Kivy. But you can probably set a new method for this.

24 Kasım 2024 Pazar tarihinde saat 02:16:48 UTC+3 itibarıyla Henrik R. şunları yazdı:

Henrik R.

unread,
Nov 24, 2024, 8:37:48 AM11/24/24
to Kivy users support
Note! Before anyone spends more time on this: It seems that chatgpt.com knows the answer!

This is the question I asked chatgpt.com:

" I am developing an app in Python and Kivy. In that app, I use a ScrollView, which contains a BoxLayout, which, among other things, contains 3 TextInput fields. Both on iOS phones and Android phones I only use 'portrait' mode, not 'landscape' mode.
When I run the app on Android and on iOS, the phone's built-in on-screen keyboard is automatically activated and displayed on the screen, because of the TextInput fields.
But apparently my app cannot automatically "see" the keyboard, so part of my ScrollView is hidden behind the on-screen keyboard.
How can my app adjust its height, so that it only uses the part of the screen that is not used by the keyboard? "

Now I will start experimenting with the answer.

Radosław Głębicki

unread,
Nov 25, 2024, 12:29:34 PM11/25/24
to Kivy users support
According to my knowledge you have to use java function from module jnius. What I saw using functions from that module keyboard is showing in time so I made "Clock.schedule_interval  to call checking size of keyboard. Is not ideal but app screen is shrinking depends size and making space for keyboard.
Part looks like this:

root_window = gActivity.getWindow()
view = root_window.getDecorView()
rect = gRect()
view.getWindowVisibleDisplayFrame(rect)
gnKeybHeight = Window.height - (rect.bottom - rect.top)

and before have to be:

gActivity = autoclass('org.kivy.android.PythonActivity')
gRect = autoclass('android.graphics.Rect')

and of course:

from jnius import autoclass

Maybe can help.

Henrik R.

unread,
Nov 27, 2024, 8:53:23 AM11/27/24
to Kivy users support
After a little help from chatgpt.com and a lot of help from copilot.microsoft.com it works! 

I have attached the main.py, buildozer.spec, and the important (python-for-android-master/) pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml file, where you have to add android:windowSoftInputMode="adjustResize" in 3 places.

A stumbling stone: In buildozer.spec I forgot to include:

# (list) Gradle dependencies to add
android.gradle_dependencies = androidx.core:core:1.12.0

You also have to point to the edited version of python-for-android:

# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
p4a.source_dir = /mnt/Data/mypython/my-p4a-copy-new/python-for-android-master/

I must admit that using AI chat machines in Python-Kivy coding and buildozer troubleshooting makes things a lot easier...

But they are not perfect...:
chatgpt.com offered a zip-file of the updated python-for-android. But it had accidentally set permissions to non-executable, so buildozer failed with ' sh.CommandNotFound: ./gradlew'
And there were other 'detours'. But the AI chatbots give a thorough answer immediately and not within hours or days.

copilot.microsoft.com seems to give more information for free than chatgpt.com (at least when you are logged in). But on chatgpt.com you can upload files, like the zip file of the whole python-for-android folder tree. On copilot.microsoft.com you can only enter 10KB. That was a problem, since buildozer.spec is 17KB.
buildozer.spec
main.py
AndroidManifest.tmpl.xml

Henrik R.

unread,
Nov 27, 2024, 8:57:25 AM11/27/24
to Kivy users support
Addition: 
A tool which I cannot live without in Linux is the Krusader 2-panel file manager! It's like a clone of TotalCommander in Windows.
I used it intensively in the above process!

Henrik R.

unread,
Nov 30, 2024, 10:39:09 AM11/30/24
to Kivy users support
NOTE! It turns out that ChatGPT and copilot.microsoft.com made things far more complicated than necessary...!

I have attached a new main.py, where the simplification is clearly visible. 
It's probably important adding the following 2 height-related settings:

class RootContent(BoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        print("RootContent(BoxLayout): x =", self.x, "y =", self.y, "height =", self.height, "width =", self.width)

        self.size_hint_y = 1
        self.height = Window.height

Henrik R.

unread,
Nov 30, 2024, 10:40:24 AM11/30/24
to Kivy users support
I forgot to attach the main.py file...
main.py

bono Amiri

unread,
Nov 30, 2024, 11:00:08 AM11/30/24
to kivy-...@googlegroups.com

Hello good time .
I just learn kivy. kivymd .
but I do not work project with kivymd .
If you can help me for working on project or introduce some one for leaders .
I will happy for helping to me


در تاریخ شنبه, نومبر ۳۰, ۲۰۲۴،‏ ۸:۰۹ ب.ظ Henrik R. <henrik.r...@gmail.com> نوشت:
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/kivy-users/2c134a7d-e712-429d-b1b5-fb94194d6e43n%40googlegroups.com.

Henrik R.

unread,
Nov 30, 2024, 12:20:52 PM11/30/24
to Kivy users support
Note: I have only tested the above on Android. I don't think it will work on iOS, because of the 'ios.get_safe_area()'...

Henrik R.

unread,
Dec 5, 2024, 12:42:42 PM12/5/24
to Kivy users support
I had to work a lot more on this before realizing some errors and mistakes that I (and ChatGPT) made. So here I include a new improved main.py demonstration, where adjusting the height to whether there is a keyboard displayed on the screen or not works on Android, and maybe on iOS (not tested yet...) IF ios.get_safe_area returns 4 zeros: ios.get_safe_area() = {'top': 0.0, 'bottom': 0.0, 'right': 0.0, 'left': 0.0}

Remember to also use your own python-for-android on Android with
android:windowSoftInputMode="adjustResize"
added 3 times in
python-for-android-master/pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml
main.py
Reply all
Reply to author
Forward
0 new messages