博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 5.0 顶部bar问题
阅读量:6709 次
发布时间:2019-06-25

本文共 2480 字,大约阅读时间需要 8 分钟。

hot3.png

public class AndroidBug5497Workaround {    // For more information, see https://code.google.com/p/android/issues/detail?id=5497    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.    public static void assistActivity (Activity activity,int statusBarHeight) {        new AndroidBug5497Workaround(activity,statusBarHeight);    }    private View mChildOfContent;    private int usableHeightPrevious;    private FrameLayout.LayoutParams frameLayoutParams;    private int statusBarHeight;    private AndroidBug5497Workaround(Activity activity,int statusBarHeight) {        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);        mChildOfContent = content.getChildAt(0);        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {            public void onGlobalLayout() {                possiblyResizeChildOfContent();            }        });        this.statusBarHeight = statusBarHeight;        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();    }    private void possiblyResizeChildOfContent() {        int usableHeightNow = computeUsableHeight();        if (usableHeightNow != usableHeightPrevious) {            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();            int heightDifference = usableHeightSansKeyboard - usableHeightNow;            if (heightDifference > (usableHeightSansKeyboard/4)) {                // keyboard probably just became visible                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight;            } else {                // keyboard probably just became hidden                frameLayoutParams.height = usableHeightSansKeyboard;            }            mChildOfContent.requestLayout();            usableHeightPrevious = usableHeightNow;        }    }    private int computeUsableHeight() {        Rect r = new Rect();        mChildOfContent.getWindowVisibleDisplayFrame(r);        return (r.bottom - r.top);    }}

 

 

oncreate里

public int getStatusBarHeight() {   int result = 0;   int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");   if (resourceId > 0) {      result = getResources().getDimensionPixelSize(resourceId);   }   return result;}

 

 

AndroidBug5497Workaround.assistActivity(this, getStatusBarHeight());

转载于:https://my.oschina.net/u/1177694/blog/678580

你可能感兴趣的文章
cookie和session使用
查看>>
hdu 5480 Conturbatio
查看>>
shell学习之变量、判断、重复动作
查看>>
企业架构研究总结(42)——企业架构与建模之ArchiMate详述(中)
查看>>
Openstack组件实现原理 — Glance架构(V1/V2)
查看>>
python操作数据库
查看>>
【已解决】WebUploader 0.1.5 安卓手机不能访问相机、IOS直接访问相机 的问题
查看>>
关于网络编程
查看>>
索引(转载)
查看>>
STL容器的删除操作
查看>>
socket中的SO_REUSEADDR
查看>>
java创建TXT文件并进行读、写、修改操作
查看>>
hdu 5176 The Experience of Love
查看>>
使用AFNetworking框架遇到的一个经典bug的解决方案
查看>>
【莫队算法】【权值分块】bzoj3236 [Ahoi2013]作业
查看>>
Levmar:Levenberg-Marquardt非线性最小二乘算法
查看>>
集训队日常训练20181110 DIV2 题解及AC代码
查看>>
DOCTYPE 与浏览器渲染模式分析
查看>>
lf 前后端分离 (3) 中间建跨域
查看>>
Python Day1
查看>>