背景
键盘高度无法获取,倒是输入框抖动问题
代码
设置
android:windowSoftInputMode=“adjustNothing”
public class KeyBoardHelper {
private static final String TAG = "KeyBoardHeightHelper";
private PopupWindow popwindow;
private int start;
private static int keyBoardHeight;
public void listenKeyBoard(View view, OnMeasureCompleteListener onMeasureCompleteListener) {
Log.i(TAG, "showMeasureWindow");
view.post(new Runnable() {
@Override
public void run() {
popwindow = new PopupWindow();
FrameLayout contentView = new MeasureLayout(view.getContext(), new MeasureLayout.onHeightChangedListener() {
@Override
public void onHeightChanged(int height) {
Log.i("qinxue","onHeightChanged height: "+height);
if (start == 0) {
start = height;
} else if (height < start) {
keyBoardHeight = start - height;
if (onMeasureCompleteListener != null) {
onMeasureCompleteListener.onKeyBoardShow(keyBoardHeight);
}
} else {
if (onMeasureCompleteListener != null) {
onMeasureCompleteListener.onKeyBoardHide();
}
}
}
});
popwindow.setContentView(contentView);
popwindow.setWidth(0);
popwindow.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
popwindow.setBackgroundDrawable(new ColorDrawable(Color.RED));
popwindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
popwindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
popwindow.showAtLocation(view.getRootView(), Gravity.NO_GRAVITY, 0, 0);
}
});
}
public static int getKeyBoardHeight() {
return keyBoardHeight;
}
public interface OnMeasureCompleteListener {
void onKeyBoardShow(int keyBoardHeight);
void onKeyBoardHide();
}
}