简体   繁体   中英

Android keyboard popupCharacters issues

I am developing a custom keyboard for android. I am trying to create a button when pressed smiley faces should popup. It has come to my understanding that android:popupCharacters is responsible for displaying a popup on the keyboard as well as android:popupKeyboard. My problem is that for example if i put android:popupCharacters=":) :(" i get a popup with each character on a button by itself. How is it done?

Thanks in advance

Read the doc carefully: http://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html#attr_android:popupCharacters

android:popupCharacters

The characters to display in the popup keyboard .

[...]

android:popupKeyboard

The XML keyboard layout of any popup keyboard.

So popupcharacters means a simpler way to create popupkeyboard. But Unicode comes and saves you from creating XML and using images: http://unicodeemoticons.com/ Try them! (Once I tried a long time ago, well displayed on 2.2 emulator, ZTE Blade and T-Mobile Pulse / Huwaei U8220).

If you don't want this workaround, the other soulution is if you go into the android SDK source, and try to reimplement the whole popup keyboard (or over-implement, if you can) to make it available for you. But anyway, if I was the user, I would be more happy for the unicode or the images, but this is only my opinion.

Create a separate xml layout for popups in xml directory as the following

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

<Row android:rowEdgeFlags="top">
        <Key android:keyLabel=":-)" android:keyOutputText=":-) "
        <Key android:keyLabel=":-)" android:keyOutputText=":-( "
    </Row>
</Keyboard>

Add as many row and/or key attributes as you like for additional smileys then use this in your keyboard xml

    <Key android:keyOutputText=":-)" android:keylabel=":-)" android:popupKeyboard="@xml/popup"/>

This will create a key ":-)" which will output the character :-) if you press it once, and use the popup xml layout when you long press it.

If you are making your own keyboard then check this following source code available which will help you a lot.

Scandinavian-keyboard

Hackers Keyboard

Android Emoji Keyboard

Also you want to change theme of your keyboard then check following link .It will give you clear idea of how to make preview layout and all. And specially if you want to check about smiley then Android Emoji Keyboard will be very useful. It uses smiley symbols in keyboard and also in preview too.

Hope this will help you.

如果我已正确理解您的查询并且您想要实现类似于Watsapp-smiley-button的东西 ,那么您可以在按钮的onClick中使用PopupWindow并为其添加不同的表情符号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM