android - 在android中实现键盘上的弹出窗口以在自定义键盘中添加图像

标签 android android-softkeyboard popupwindow

可以从键盘列表中选择该键盘,并且用户可以从任何应用程序中使用它。 只需实现弹出窗口即可在自定义软键盘中的键盘上添加图像

最佳答案

您必须创建一个扩展 PopupWindow 的类

public class CustomPopup extends PopupWindow {
    Context mContext;
    View rootView;

    public CustomPopup(View rootView, Context mContext){
        super(mContext);
        this.mContext = mContext;
        this.rootView = rootView;
        View customView = createCustomView();
        setContentView(customView);
        setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        setSize(250, LayoutParams.MATCH_PARENT);
    }

    private View createCustomView(){
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.custom_popup, null, false);

        return view;
    }

    public void setSize(int width, int height){
        setWidth(width);
        setHeight(height);
    }

}

然后在您的 SoftKeyboard 类中使用它

CustomPopup popupWindow;

public View onCreateInputView() {
        final View root = getLayoutInflater().inflate(R.layout.input, null);

        popupWindow = new CustomPopup(root, this);

        return root;
}

这是显示弹出窗口的方法。请注意,mInputView 是您的keyboardView 变量

private void showPopup() {
        int height = mInputView.getHeight();
        popupWindow.setSize(LayoutParams.MATCH_PARENT, height);
        popupWindow.showAtLocation(mInputView.getRootView(), Gravity.BOTTOM, 0, 0);
        final InputMethodManager mInputMethodManager = (InputMethodManager) getBaseContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        mInputMethodManager.showSoftInput(mInputView, 0);
    }

关于android - 在android中实现键盘上的弹出窗口以在自定义键盘中添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38110602/

相关文章:

安卓工作室 : How to change a button's text onClick

java - 当 editText 聚焦且键盘打开时如何移动 View ?

css - z-index 不能与溢出结合使用

flutter - PopUpWindow弹出后如何调用setState(重建页面)?

android - 在发布时获得多个相同的请求 pubnubv4 rails

android - 将 JSON 响应转换为 JAVA 对象

android - 如何为android软键盘中的按钮设置onClickListener?

android - 键盘以横向模式全屏打开

javascript - 提交表单时 Angular 事件成功打开弹​​出窗口

android - 使用 DataBinding 测试 fragment 时错误膨胀类 fragment