Android softkeyboard popup view on key long press

时光毁灭记忆、已成空白 提交于 2019-12-09 06:07:53

问题


I am developing Android soft 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" >

But when I longPress on "0" key popup with ")" shows, but it stays there until I press "X" button or ")" character.

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

Anyone can help?

Thanks!!


回答1:


I think you will need to create your own popup in this case, using PopupWindow or Dialog.

then you go into your keyboard and overwrite your onRelease method, like this:

@Override
public void onRelease(int primaryCode) {  
    myPopupWindow.dismiss();
}

To make your own popupWindow for keyboard see this thread: Android custom keyboard popup keyboard on long press



来源:https://stackoverflow.com/questions/32218574/android-softkeyboard-popup-view-on-key-long-press

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