Android自定义键盘popup式键盘上长按

我有自定义的Android键盘

public class CustomKeyboard extends Keyboard{...} public class CustomKeyboardView extends KeyboardView{...} public class CustomKeyboardIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener{...} 

在一些键上,我有popupKeyboardpopupCharacters

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

但是,当我长按“0”键popup与“)”显示,但它留在那里,直到我按“X”button或“)”字符。 它看起来像这样:
我的键盘

我只想在手指上打开它。 像三星或HTC键盘上的东西:
三星键盘

有人能帮助我吗?

编辑至less可以改变这个popup窗口的外观? 我希望它具有与我制作的全键盘相同的背景和键盘/

Solutions Collecting From Web of "Android自定义键盘popup式键盘上长按"

您可以使用PopupWindow类并使用自定义布局进行填充。

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

并长按

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

点击popup窗口,您可以closures它

 popup.dismiss();