Android custom keyboard popup keyboard on long press

前端 未结 1 1981
名媛妹妹
名媛妹妹 2020-12-13 15:00

I have custom Android keyboard:

    public class CustomKeyboard extends Keyboard{...}  

    public class CustomKeyboardView extends KeyboardView{...}

    p         


        
相关标签:
1条回答
  • 2020-12-13 15:42

    You can use PopupWindow class and populate it with custom layout.

    View custom = LayoutInflater.from(context)
        .inflate(R.layout.your_layout, new FrameLayout(context));
    PopupWindow popup = new PopupWindow(context);
    popup.setContentView(custom);
    

    and on long press

    //Get x,y based on the touch position
    //Get width, height based on your layout
    if(popup.isShowing()){
        popup.update(x, y, width, height);
    } else {
        popup.setWidth(width);
        popup.setHeight(height);
        popup.showAtLocation(yourKeyboardView, Gravity.NO_GRAVITY, x, y);
    }
    

    On click in the popup you can dismiss it

    popup.dismiss();
    
    0 讨论(0)
提交回复
热议问题