This commit is contained in:
haomingming
2026-11-09 10:36:42 +08:00
parent dcc4606b7c
commit 813771abd2
4 changed files with 9 additions and 11 deletions
@@ -565,7 +565,10 @@ class BrowserActivity : AppCompatActivity(), RemoteControlCallback {
cursorOverlay?.post { initCursorPosition() }
// 不监听 overlay 的 layout 变化,避免底部左右移动时 webView.scrollBy 触发布局导致 clampCursorToBounds 错误改动 cursorY;全屏切换等时由调用方主动 clamp
webView.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) hideKeyboard() }
// 仅当焦点切到网页非输入区域时收起地址栏残留的软键盘;若用户直接点击网页内的输入框(onCheckIsTextEditor=true),不能收起键盘
webView.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus && !webView.onCheckIsTextEditor()) hideKeyboard()
}
// 弹窗(DialogFragment)显示时隐藏光标、销毁时恢复,避免弹窗遮挡光标(按弹窗对象去重,重复回调也不会累积)
dialogCursorLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
@@ -5,9 +5,8 @@ import android.util.AttributeSet
import android.webkit.WebView
/**
* TV 场景专用 WebView:
* - 不作为文本编辑器,避免系统软键盘在网页输入框获得焦点时弹出
* - 文字输入统一通过遥控网页转发
* 自定义 WebView:
* - 保留系统默认的 onCheckIsTextEditor() 行为(仅在网页内 input/textarea 等可编辑元素聚焦时返回 true,以正常唤起手机/系统输入法)
* - 暴露滚动监听,支持向下滚动自动收起工具栏,向上滚动自动唤出
*/
class RemoteWebView @JvmOverloads constructor(
@@ -19,11 +18,6 @@ class RemoteWebView @JvmOverloads constructor(
/** 滚动变化监听:(scrollX, scrollY, oldScrollX, oldScrollY) */
var onScrollChangeListener: ((Int, Int, Int, Int) -> Unit)? = null
override fun onCheckIsTextEditor(): Boolean {
// 告诉系统这不是文本编辑控件,避免为网页内的 input/textarea 弹出软键盘
return false
}
override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
super.onScrollChanged(l, t, oldl, oldt)
onScrollChangeListener?.invoke(l, t, oldl, oldt)