Repository navigation
fix(android): 键盘弹出时底部系统栏保持主题浸入 - #8
Merged
Merged
Conversation
A fully transparent navigation bar is replaced by the framework default (white, not the app theme) once an input is focused and the IME is shown. On tablets the gesture handle stays visible, so dark mode turns that strip pure white. Pin an opaque theme color, disable contrast enforcement, and reapply it when insets or window focus change. Co-authored-by: xiufeigo <xiufeigo@users.noreply.github.com>
xiufeigo
marked this pull request as ready for review
October 17, 2026 06:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Android 平板上点进聊天输入框、软键盘弹出后,底部手势条 / 导航栏不再浸入,和页面底色脱开。浅色主题下这条会变成纯白,和桉树浅色(约
#f4f7f5)对不上;深色主题下同样是纯白,尤其明显。根因
导航栏被设成了
Color.TRANSPARENT,沉浸靠decorView的主题色从透明栏后面透出来。输入框获焦、IME inset 到来时,这条假设不成立:enableEdgeToEdge()的默认SystemBarStyle.auto会把isNavigationBarContrastEnforced设为 true。三键导航因此叠上约 90% 不透明的白 scrim(DefaultLightScrim = #E6FFFFFF)。主题同步每 800ms 把导航栏重新写成透明,但没有再次关掉对比度强制,所以键盘期间白条会留住。setNavigationBarColor时改读 window background,并且要求它是ColorDrawable。原先只调用decorView.setBackgroundColor(),窗口背景仍是 Material 日间主题的白底。键盘收起时窗口全屏、透明栏盖在主题色
decorView上,所以看起来是浸入的。问题只在获焦 / IME 出现之后。修复
MainActivity.applySystemBars()统一钉色,主题同步、JS bridge、inset 变化和窗口重新获焦都会再写一次:--color-bg-100,不再用透明。状态栏仍透明,顶部继续由页面自己画。FLAG_TRANSLUCENT_*,避免setNavigationBarColor被忽略。window.background、decorView、android.R.id.content和 WebView 都铺成同一主题色,inset padding 露出的缝和 Android 15 的 window background 回退不再是白。enableEdgeToEdge改用SystemBarStyle.light(TRANSPARENT, TRANSPARENT),避免 auto 样式把对比度强制打开。setSystemBars改到主线程执行(JavascriptInterface不在 UI 线程)。底部 inset 算法没变:
max(IME, systemBars),键盘仍然把 WebView 顶上去。验证
这台环境没有 Android SDK / 平板模拟器,没有做真机或模拟器点按。
已核对的路径:
onWindowFocusChanged会把同一不透明色再钉回去,不会被透明覆盖。isAppearanceLightNavigationBars = true(深色图标);深色主题为 false(浅色图标)。判定与原来的isColorLight(color) && mode != "dark"一致。decorView主题色,关闭键盘的浸入外观不变。建议在平板上再看一眼:浅色 / 深色各聚焦一次输入框,手势条应与页面底色连成一块,深色模式不能是纯白;收起键盘后状态栏和底栏仍浸入。三键导航也看一下,确认没有白 scrim。