android键盘监听

//contentlayout是最外层布局View mChildOfContent;int usableHeightPrevious;


mChildOfContent = contentlayout.getChildAt(0);mChildOfContent.getViewTreeObserver()               .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {                      public void onGlobalLayout() {   
                    Rect r = new Rect();                           mChildOfContent.getWindowVisibleDisplayFrame(r);    
                    int usableHeightNow = r.bottom - r.top;    
                    if (usableHeightNow != usableHeightPrevious) {        
                        int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();       
                        int heightDifference = usableHeightSansKeyboard - usableHeightNow;       
                        if (heightDifference > (usableHeightSansKeyboard / 4)) {           
                            // 键盘弹出        
                        } else {            
                            // 键盘收起         
                        }       
                    mChildOfContent.requestLayout();       
                    usableHeightPrevious = usableHeightNow;    
                }            }});
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010505059/article/details/80693081
个人分类: android
想对作者说点什么? 我来说一句

键盘显示和隐藏监听

2016年11月24日 3.16MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭