-
Notifications
You must be signed in to change notification settings - Fork 131
Description
Nav bar obscures keyboard when used on Android 15
When running on a device running API 35 or above, the keyboard is partially obscured by system bars. This issue also affects the main activity.
Symptoms
Running on an emulator with an API level 35 image, or on my phone, the main activity and keyboard are obscured.
This is the activity with its content scrolled up as far as it will go:
and in landscape:
And here is the keyboard:
This also affects the default keyboard in the emulator's system image (which is an AOSP one without Google Play). It does not affect the default Samsung keyboard on my phone.
Cause
Android 15 puts apps in "edge to edge" mode, where they are drawn under the system bars and must adjust their padding accordingly.
That explains the obscured parts of the views, but I have no idea why the phenomenon in the second last image occurs, where the left edge of the keyboard is not obscured but the width seems not to be sufficiently narrower to fit it all on screen.
Attempted fix
I am not very familiar with Android development, so I have been down a rabbit hole trying to fix this.
The first thing I tried, is reverting targetSdk to 34. I thought that Android would try to make older apps work as if they were running on an older version of Android. That did not work. Of course that would not be a real solution anyway, long term.
edit: There was a paragraph here about my misunderstanding of WindowInsets, specifically arising from the fact that I thought WindowInsets.getInsets(int) returned a WindowInsets, but it returns an Insets
In any case, it didn't work.
But it seems there is also a fitsSystemWindows attribute of views which can be set in a layout file or at runtime. That fixes the activity views, but not the keyboard. I think it may be to do with the keyboard being inside a subclass of Dialog called SoftInputWindow, which is used by the InputMethodService class. Perhaps that doesn't get WindowInsets applied automatically. I have no idea.
Here is the tiny patch that adds fitsSystemWindows everywhere: larrychips/codeboard@c552594
diff --git a/app/src/main/java/com/gazlaws/codeboard/layout/ui/KeyboardUiFactory.java b/app/src/main/java/com/gazlaws/codeboard/layout/ui/KeyboardUiFactory.java
index 8010be4..5922d34 100644
--- a/app/src/main/java/com/gazlaws/codeboard/layout/ui/KeyboardUiFactory.java
+++ b/app/src/main/java/com/gazlaws/codeboard/layout/ui/KeyboardUiFactory.java
@@ -31,6 +31,7 @@ public class KeyboardUiFactory {
View view = createKeyView(context, key, uiTheme);
layout.addView(view,params);
}
+ layout.setFitsSystemWindows(true);
return layout;
}
diff --git a/app/src/main/res/layout/codeboard_intro1.xml b/app/src/main/res/layout/codeboard_intro1.xml
index d24bc51..5914d19 100644
--- a/app/src/main/res/layout/codeboard_intro1.xml
+++ b/app/src/main/res/layout/codeboard_intro1.xml
@@ -3,7 +3,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
- android:orientation="vertical">
+ android:orientation="vertical"
+ android:fitsSystemWindows="true">
<TextView
android:layout_width="wrap_content"
@@ -43,4 +44,4 @@
android:layout_marginBottom="64dp"
android:src="@drawable/enable_screenshot" />
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/app/src/main/res/layout/codeboard_intro2.xml b/app/src/main/res/layout/codeboard_intro2.xml
index 3a80e75..78a39b2 100644
--- a/app/src/main/res/layout/codeboard_intro2.xml
+++ b/app/src/main/res/layout/codeboard_intro2.xml
@@ -3,7 +3,8 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="@color/colorPrimaryDark">
+ android:background="@color/colorPrimaryDark"
+ android:fitsSystemWindows="true">
<TextView
android:layout_margin="48dp"
android:textStyle="bold"
@@ -33,4 +34,4 @@
android:src="@drawable/icon_large"
android:layout_marginBottom="64dp"/>
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/app/src/main/res/layout/new_activity_main.xml b/app/src/main/res/layout/new_activity_main.xml
index 2a09f1a..ed1d87a 100644
--- a/app/src/main/res/layout/new_activity_main.xml
+++ b/app/src/main/res/layout/new_activity_main.xml
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>