您的位置:首页 > 移动开发 > Android开发

【Android】4.4以上使用透明状态栏后布局被软键盘遮挡的解决办法

2016-01-15 11:49 495 查看
/**
* 解决透明状态栏下,布局无法自动拉起的问题
* 手动设置View的高度
*/
private void setInput() {
final View rootView = ((ViewGroup) this.findViewById(android.R.id.content))
.getChildAt(0);
final View decorView = getWindow().getDecorView();
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override
public void onGlobalLayout() {
Rect rect= new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
int screenHeight = decorView.getRootView().getHeight();
int heightDifferent = screenHeight - rect.bottom;
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) rootView.getLayoutParams();
lp.setMargins(0, 0, 0, heightDifferent);
rootView.requestLayout();
}
});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: