我有定制的安卓键盘:

    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”键弹出时,会显示“0”,但直到我按“x”按钮或“1”)字符时,它才会消失。看起来是这样的:
我只想在我手指着的时候打开它。类似三星或HTC键盘:
有人能帮我吗?
编辑是否至少可以更改此弹出窗口的外观?我希望它的背景和按键和我做的整个键盘一样/

最佳答案

您可以使用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.dismiss();

07-26 09:42
查看更多