Android custom keyboard popup keyboard on long press
Asked Answered
P

1

20

I have custom Android keyboard:

    public class CustomKeyboard extends Keyboard{...}  

    public class CustomKeyboardView extends KeyboardView{...}

    public class CustomKeyboardIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener{...}  

On some keys, I have popupKeyboard and popupCharacters:

<Key android:codes="144" android:keyLabel="0" android:popupKeyboard="@xml/key_popup" android:popupCharacters=")" android:keyEdgeFlags="right"/>

xml/key_popup.xml:

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
      android:keyWidth="10%p"
      android:horizontalGap="0px"
      android:verticalGap="0px"
      android:keyHeight="@dimen/key_height" >
</Keyboard>

But when I longPress on "0" key popup with ")" shows, but it stays there until I press "X" button or ")" character. It looks like this:
My keyboard

And I want it to be opened only while I am holding a finger on. Something like on Samsung or HTC keyboard:
Samsung keyboard

Can someone help me please?

EDIT Is it at least possible to change the appearance of this popup? I want it to have same background and keys as whole keyboard I have made/

Panay answered 1/4, 2015 at 11:57 Comment(7)
anybody got solution for this question ?Mindymine
I think you have to make custom views for everything if you want to customize the keyboard... But I don't know how.Panay
This link help full you #7753080Unpolled
I'm wanting to do something similar. How did you solve your problem?Sexagenarian
I'm going to use this method: stackoverflow.com/a/18462324Sexagenarian
did you find any solution please updatePellmell
@MateenChaudhry Did you found any solution please?Almsman
A
7

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();
Antislavery answered 27/10, 2015 at 9:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.