cocosCreator2.4 Android 输入法遮挡

这里是 调用显示系统的输入法,然后在 Cocos2dxEditBox.java 创建UI,用于处理输入,这里可以看到会ui 会被系统的输入法遮挡,无法点击,是因为 计算ui位置时没有算上刘海区域,需要处理一下:

java 复制代码
        private int getTopSpecialHeight(Context context) {
            int result = 0;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                // 执行安全区域检测
                WindowInsets windowInsets = getRootView().getRootWindowInsets();
                if (windowInsets != null) {
                    DisplayCutout displayCutout = windowInsets.getDisplayCutout();
                    if (displayCutout != null) {
                        return displayCutout.getSafeInsetTop();
                    }
                }
            }
            return result;
        }

然后修改 Cocos2dxEditText.this.setTopMargin(r.bottom); 为:

java 复制代码
        int delta = getTopSpecialHeight(getContext());
        Cocos2dxEditText.this.setTopMargin(r.bottom-delta);

其它网上还有一个解决方案:CocosCreator安卓原生平台手机输入法遮挡文本输入框

这个方案是将游戏整个页面上抬,但是我这边测试有时上抬刘海高度,有时上台键盘高度那么高。而我们有些玩法的输入框在游戏顶部区域就导致完全看不到输入的是什么内容。

相关推荐
broadview_java1 天前
使用 ConstraintLayout 构建自适应界面
android
wy3136228211 天前
android——开发中的常见Bug汇总与解决方案(闪退)
android·bug
小小测试开发1 天前
实战派SQL性能优化:从语法层面攻克项目中的性能瓶颈
android·sql·性能优化
QuantumLeap丶1 天前
《Flutter全栈开发实战指南:从零到高级》- 26 -持续集成与部署
android·flutter·ios
StarShip1 天前
从Activity.setContentView()开始
android
千里马学框架1 天前
重学SurfaceFlinger之Layer显示区域bounds计算剖析
android·智能手机·sf·安卓framework开发·layer·surfaceflinger·车载开发
nono牛1 天前
安卓休眠与唤醒流程
android
二流小码农1 天前
鸿蒙开发:个人开发者如何使用华为账号登录
android·ios·harmonyos
StarShip1 天前
Android View框架概览
android·计算机图形学
愤怒的代码1 天前
解析Android内存分析的指标
android·app