implement popup window on keyboard in android to add images in custom keyboard

冷暖自知 提交于 2019-12-11 01:54:04

问题


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


回答1:


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);
    }

}

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;
}

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);
    }


来源:https://stackoverflow.com/questions/38110602/implement-popup-window-on-keyboard-in-android-to-add-images-in-custom-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!