长preSS的Andr​​oid定制的键盘弹出键盘

长preSS的Andr​​oid定制的键盘弹出键盘

本文介绍了长preSS的Andr​​oid定制的键盘弹出键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义Android键盘:

I have custom Android keyboard:

    public class CustomKeyboard extends Keyboard{...}

    public class CustomKeyboardView extends KeyboardView{...}

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

在某些键,我有 popupKeyboard popupCharacters

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

XML / key_popup.xml:

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键弹出与)节目,余长preSS但它在那里等待直到我preSS的X按钮或)的字符。它看起来像这样:

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:

和我希望它是只开了,而我拿着一个手指。像三星或HTC的键盘:

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

有人能帮助我吗?

修改是它至少可以改变这个弹出的外观?我希望它有相同的背景,并作为全键盘我已/键

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/

推荐答案

您可以使用 PopupWindow 类以及自定义布局填充它。

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

和长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();

这篇关于长preSS的Andr​​oid定制的键盘弹出键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:58