public class KeyboardPatch
{
private Activity activity;
private View decorView;
private View contentView;
/**
* 构造函数
* @param act 需要解决bug的activity
* @param contentView 界面容器,activity中一般是R.id.content,也可能是Fragment的容器,根据个人需要传递
* */
public KeyboardPatch(Activity act, View contentView)
{
this.activity = act;
this.decorView = act.getWindow().getDecorView();
this.contentView = contentView;
}
/**
* 监听layout变化
* */
public void enable()
{
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
if (Build.VERSION.SDK_INT >= 19)
{
decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
}
}
/**
* 取消监听
* */
public void disable()
{
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
if (Build.VERSION.SDK_INT >= 19)
{
decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
}
}
private ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
Rect r = new Rect();
decorView.getWindowVisibleDisplayFrame(r);
int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels;
int diff = height - r.bottom;
if (diff != 0)
{
if (contentView.getPaddingBottom() != diff)
{
contentView.setPadding(0, 0, 0, diff);
}
}
else
{
if (contentView.getPaddingBottom() != 0)
{
contentView.setPadding(0, 0, 0, 0);
}
}
}
};
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有