在android中的键盘上实现弹出窗口以在自定义键盘中添加图像 [英] implement popup window on keyboard in android to add images in custom keyboard

查看:115
本文介绍了在android中的键盘上实现弹出窗口以在自定义键盘中添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This keyboard can be select from the keyboard list and user can use it from any application. just implement popup-window to add images on keyboard in custom soft keyboard

推荐答案

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

You have to create a class that extends 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类中使用它

Then use it in your SoftKeyboard Class

CustomPopup popupWindow;

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

        popupWindow = new CustomPopup(root, this);

        return root;
}

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

This is how to show the popup. Note that mInputView is your keyboardView variable

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中的键盘上实现弹出窗口以在自定义键盘中添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆