KeyboardView

Introduction: 自定义安全键盘
More: Author   ReportBugs   
Tags:
效果图:keyboardView

具体使用

editView.setEditView(llKeyboard, keyboardView, true);

editView.setOnKeyboardListener(new EditView.OnKeyboardListener() {
    @Override
    public void onHide(boolean isCompleted) {
        if (height > 0) {
            llGuan.scrollBy(0, -(height + DensityUtil.dp2px(MainActivity.this, 16)));
        }

        if (isCompleted) {
            Log.i("", "你点击了完成按钮");
        }
    }

    @Override
    public void onShow() {
        llGuan.post(new Runnable() {
            @Override
            public void run() {
                //pos[0]: X,pos[1]: Y
                int[] pos = new int[2];
                //获取编辑框在整个屏幕中的坐标
                editView.getLocationOnScreen(pos);
                //编辑框的 Bottom 坐标和键盘 Top 坐标的差
                height = (pos[1] + editView.getHeight())
                        - (ScreenUtil.getScreenHeight(MainActivity.this) - keyboardView.getHeight());
                if (height > 0) {
                    //编辑框和键盘之间预留出 16dp 的距离
                    llGuan.scrollBy(0, height + DensityUtil.dp2px(MainActivity.this, 16));
                }
            }
        });
    }

    @Override
    public void onPress(int primaryCode) {

    }
});

llKeyboard 为包裹键盘的父布局,llGuan 为包裹输入框的父布局。

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools