其他分享
首页 > 其他分享> > 直播app源代码,监听软键盘

直播app源代码,监听软键盘

作者:互联网

直播app源代码,监听软键盘实现的相关代码
1。ManiFest 增加

android:windowSoftInputMode="adjustResize"

2。添加监听,其中rootview是页面根布局

rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                //r will be populated with the coordinates of your view that area still visible.
                rootView.getWindowVisibleDisplayFrame(r);
 
                int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);
                int rootviewHeight = rootView.getRootView().getHeight();
                if (rootviewHeight-r.bottom > 200) { // if more than 100 pixels, its probably a keyboard...do something here
                    LogUtil.d("onGloable","键盘弹出");
                    llVoiceRootview.setVisibility(View.VISIBLE);
                }else {
                    LogUtil.d("onGloable","键盘隐藏");
                    llVoiceRootview.setVisibility(View.GONE);
                }
 
 
            }
        });

以上就是 直播app源代码,监听软键盘实现的相关代码,更多内容欢迎关注之后的文章

标签:app,rootView,软键盘,直播,源代码,监听
来源: https://blog.csdn.net/yb1314111/article/details/115484384