Android: stop adding keyboard padding on top of the system's own resize, which left an empty block above the keyboard

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 14:15:09 +02:00
co-authored by Claude Opus 5.5
parent edea4ce0d2
commit 6a6971e1cb
2 changed files with 6 additions and 12 deletions
@@ -15,7 +15,7 @@
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustNothing"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
@@ -1,9 +1,7 @@
package de.mrterm.app;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebView;
import androidx.activity.OnBackPressedCallback;
@@ -28,24 +26,20 @@ public class MainActivity extends BridgeActivity {
}
});
// Edge-to-Edge: Abstände für Statusleiste, Navigationsleiste und Tastatur setzt allein diese Ansicht.
// Die Insets werden danach verbraucht, damit WebView/System nicht ein zweites Mal verkleinern.
// Edge-to-Edge: Ränder für Status- und Navigationsleiste setzt diese Ansicht. Den Platz für die Tastatur
// schafft Android/WebView selbst – hier nur melden, ob sie offen ist (sonst würde doppelt verkleinert).
View parent = (View) web.getParent();
parent.setBackgroundColor(0xFF14161D);
final boolean[] imeOpen = { false };
// Vor Android 11 kommen Tastatur-Insets nicht zuverlässig: dort verkleinert das System das Fenster
final boolean legacyIme = Build.VERSION.SDK_INT < Build.VERSION_CODES.R;
if (legacyIme) getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
ViewCompat.setOnApplyWindowInsetsListener(parent, (v, insets) -> {
Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
int ime = legacyIme ? 0 : insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
v.setPadding(bars.left, bars.top, bars.right, Math.max(ime, bars.bottom));
boolean open = ime > 0;
boolean open = insets.isVisible(WindowInsetsCompat.Type.ime());
v.setPadding(bars.left, bars.top, bars.right, open ? 0 : bars.bottom);
if (open != imeOpen[0]) {
imeOpen[0] = open;
web.evaluateJavascript("window.mrtermIme && window.mrtermIme(" + open + ")", null);
}
return WindowInsetsCompat.CONSUMED;
return insets;
});
}
}