【问题标题】:Embedding emoji(emoticons images) to custom softkeyboard android将表情符号(表情符号图像)嵌入到自定义软键盘 android
【发布时间】:2015-02-20 15:10:27
【问题描述】:

我创建了一个自定义软键盘 (IME),我们可以在其中添加自定义表情符号。

每当我尝试添加我的表情符号时。它会覆盖最后输入的文本。我的意思是它不会附加表情符号,除非它覆盖它。如何将表情符号添加到 currentInputConnection

例如

i image write  hello image abcimage          ///where image represents emoji

变成了

i image write hello image image

//我可以很容易地在空格之后添加图像,或者我可以很容易地重复添加图像。

当我添加文本时,它会附加到表情符号,但是当我在输入一些文本后添加表情符号时,它会删除文本,然后自行添加(表情符号图像)。

仅出于测试目的,我将表情符号代码放在 shift 键上

问题代码

else if (primaryCode == Keyboard.KEYCODE_SHIFT) 
        {
        //  this.handleShift();

            //this.mComposing.append(getSmiledText(getApplicationContext(), ":)"));

             ImageGetter imageGetter = new ImageGetter() 
                {
                    public Drawable getDrawable(String source) {
                        Drawable d = getResources().getDrawable(R.drawable.e041);
                        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                        return d;
                    }
                };

                Spanned cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.e041) + "'/>", imageGetter, null);

              //  getCurrentInputConnection().commitText(cs, 1);

               // this.mComposing.append(cs);


            //getCurrentInputConnection().commitText(getSmiledText(getApplicationContext(), ":)"), 1);


             getCurrentInputConnection().beginBatchEdit();


             getCurrentInputConnection().commitText(cs, 1);

             getCurrentInputConnection().endBatchEdit();


            //getCurrentInputConnection().setComposingText(cs, 1); // it is giving wrong 


        } 

并尝试了多种方法来解决它,一些尝试过的代码显示在cmets中

简单的话:我想将表情符号图像附加到文本中,但是当我将图像添加到文本时,它会删除书面文本,我该如何解决。 无法显示完整的源代码,它很长。在我的课堂上问我是否需要任何方法

相关链接:

add custom image as Emoji in android

https://stackoverflow.com/questions/24100615/cannot-add-an-image-to-my-keyboard-service

Implementations of Emoji (Emoticon) View/Keyboard Layouts

提前致谢。

【问题讨论】:

  • 您的文本是提交还是组成文本?在第二种情况下,您必须在添加图像之前提交文本。
  • 此方法仅展示如何将图像添加到软键盘,
  • 我知道。当您之前添加文本时,它是作为组合文本添加的吗?因为如果是这样,添加图像时消失的文本是设计的。

标签: android android-softkeyboard android-input-method


【解决方案1】:

我也尝试过,但总是得到“obj”。最后我找到了一个解决方案试试这个。

不要添加drawables,只需像这样通过他们的uniCodes添加表情符号..

getCurrentInputConnection().commitText((CharSequence)"\ud83c\udfb5", 1);

它完美地为我工作。并且还从您的代码中删除 beginBatchEdit 和 endBatchEdit。

谢谢

【讨论】:

猜你喜欢
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 2016-03-04
  • 2015-11-23
  • 2015-10-16
  • 2020-04-25
  • 1970-01-01
  • 2014-12-08
相关资源
最近更新 更多