Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当采用今日头条的兼容适配方案时,底部的虚拟返回键会挡住部分输入框的布局。 #196

Open
chenciyaun opened this issue Jun 20, 2023 · 5 comments

Comments

@chenciyaun
Copy link

当采用今日头条的兼容适配方案时,底部的虚拟返回键会挡住部分输入框的布局。原因是计算虚拟键的高度计算错误,建议采用系统的资源的API Resources.getSystem() 来获取虚拟返回键的高度,而不是当前的上下文。这个坑很浪费时间定位呀,恳请兼容一下。

@HeroZ-Dodge
Copy link
Collaborator

你好,请问你遇到这个问题的设备信息是什么。
另外你提到获取虚拟返回键的高度,具体是指哪部分源码

@chenciyaun
Copy link
Author

设备名称:华为P9,型号VIE-AL10 EMUI版本8.0.0 安卓版本8.0.0 有虚拟返回键盘

采用头条的适配方案在聊天界面设置
@OverRide
public Resources getResources() {
return AdaptScreenUtils.adaptWidth(super.getResources(), 360);
}

就会出现底部的虚拟返回键会挡住部分输入框的布局。

经过定位分析发现是工具类DisplayUtil 131行 getNavigationBarHeight 获取的高度减少了一半,带有虚拟返回键的手机才会出现这个问题。

解决方案:修改DisplayUtil 154行的 getInternalDimensionSize这个方法
private fun getInternalDimensionSize(key: String): Int {
val res = Resources.getSystem()// 关键修改点
var result = 0
val resourceId = res.getIdentifier(key, Constants.DIMEN, Constants.ANDROID)
if (resourceId > 0) {
result = res.getDimensionPixelSize(resourceId)
}
return result
}

审查合理的话,希望可以更新下。我现在的修改是直接下载源码进行修改的。

@HeroZ-Dodge
Copy link
Collaborator

getInternalDimensionSize 用于获取当前页面导航栏的高度,通过Resources.getSystem() 获取的高度和实际高度会有差异,会导致测量高度不准确

@skyCracks
Copy link

建议这样修改兼容性会更强一些:
fun getInternalDimensionSize(context: Context, key: String): Int {
val result = 0
try {
val resourceId = Resources.getSystem().getIdentifier(key, Constants.DIMEN, Constants.ANDROID)
if (resourceId > 0) {
val sizeOne = context.resources.getDimensionPixelSize(resourceId)
val sizeTwo = Resources.getSystem().getDimensionPixelSize(resourceId)
return if (sizeTwo >= sizeOne && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
key != Constants.STATUS_BAR_HEIGHT_RES_NAME)
) {
sizeTwo
} else {
val densityOne = context.resources.displayMetrics.density
val densityTwo = Resources.getSystem().displayMetrics.density
val f = sizeOne * densityTwo / densityOne
(if (f >= 0) f + 0.5f else f - 0.5f).toInt()
}
}
} catch (ignored: NotFoundException) {
return 0
}
return result
}

@15359947959
Copy link

15359947959 commented Apr 20, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants