Android适配虚拟按键-亲测华为小米手机有效
应用上传华为应用市场,结果被拒,原因是真人测试手机带虚拟按键,结果导致虚拟按键和屏幕某点击事件冲突,一点击就会退出到手机主页。废话不多说,直接上代码。
方案一:最简单的方法是布局文件根目录中添加 android:fitsSystemWindows=“false”,可以自动根据屏幕适配,但是我的项目用到了沉浸式状态栏,所以这个方法直接Pass掉.
方案二:调用:
BaseActivity中:
UIUtils.assistActivity(getRootView(this), this);
private static View getRootView(Activity context)
{
return ((ViewGroup)context.findViewById(android.R.id.content)).getChildAt(0);
}
UIUtils中:
/**
* 关联要监听的视图
*
* @param viewObserving
*/
public static void assistActivity(View viewObserving, Context context) {
new UIUtils(viewObserving, context);
}
private UIUtils(View viewObserving, Context context) {
mViewObserved = viewObserving;
//给View添加全局的布局监听器
mViewObserved.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
resetLayoutByUsableHeight(co

本文介绍了在应用上传华为应用市场时遇到的虚拟按键与屏幕点击事件冲突的问题。通过两种方案进行解决:一是设置布局文件根节点的android:fitsSystemWindows属性为"false",二是使用代码辅助适配,具体涉及UIUtils的辅助方法。

1564

被折叠的 条评论
为什么被折叠?



