小编Igo*_*gor的帖子

ImageText上的ImageSpan(表情符号).使用SwiftKey键盘不起作用

我正在做一个简单的聊天应用程序,我想在编写消息时在edittext上显示表情符号.

我有这个来识别图像将通过ImageSpan从图像中取代(只有在EditText上插入表情符号时才会调用此字符):

for (index = start; index < start+num_chars; index++) {
        if (index + 1 > editable.length())
            continue;  
          if(emoticons.containsKey(editable.subSequence(index, index + 1).toString())){
            int length=1; 

            Drawable drawable = context.getResources().getDrawable(emoticons.get(editable.subSequence(index, index + 1).toString()));
            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();


            int size=Utils.GetDipsFromPixel(context, (int)(textSize*1.3));

            Drawable d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, size, size, true));
            int dWidth = d.getIntrinsicWidth();
            int dHeight = d.getIntrinsicHeight();

            d.setBounds(0 , -dHeight, dWidth, 0);
            ImageSpan span;
            span = new ImageSpan(d,ImageSpan.ALIGN_BASELINE);
            editable.setSpan(span, index, index + length,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            index += length - 1;
          }

      }
Run Code Online (Sandbox Code Playgroud)

我正在使用SPAN_EXCLUSIVE_EXCLUSIVE标签来设置范围,但是我遇到了swiftkey键盘的问题,因为当我在edittext中插入一个笑脸时,我在imageSpan之后写的所有内容都保持在图像下方(如SPAN_EXCLUSIVE_INCLUSIVE).使用Android默认键盘我没有这个问题.

我只想在EditText上使用whatsapp应用程序相同的行为. …

android android-edittext spannable

6
推荐指数
1
解决办法
9256
查看次数

标签 统计

android ×1

android-edittext ×1

spannable ×1