android用图标

时间:2016-08-14 16:07:40

标签: android

我有一系列的emogis:

 String rr [] = {":)",":D",":(",":'(",":P",":P","3:)","o.O",";)",":O","-_-",">:O",":*","<3","^_^","8-)","8|","(^^^)",
        ":|]",">:(",":v",":/",":3","☺","(y)",":poop:",":putnam:","<(\")","✌","☀","☁","☔","⚡","✨","⭐","✳", 

        "","","",
        "","","〽","","","","","","","" 
};

我需要替换此String

String mm = "Hello wold :D :P try emotions ";

我把它们作为图标的所有那些情感也是如此可以替代所有 简单的字符串到图标并将它们附加到textView

我想要什么

这是我的字符串

String mm = "Hello wold :D :P try emotions ";

有三种情绪

我有图标数组

我想用字符串替换字符串中的所有情感

      int icon[] = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e};
      String rr [] = {":)",":D",":(",":'(",":P",":P","3:)","o.O",";)",":O","-_-",};

所以在字符串String rr []中找到它们并用icon[]数组替换它们,以便在textView中显示它们,如果这样正确,我该如何找到和替换

1 个答案:

答案 0 :(得分:0)

您可以将SpannableStringTextView一起使用。这种类型的字符串允许您在TextView

中使用内嵌图像

对于每个情感图标,您需要创建ImageSpan。此ImageSpan可以作为内嵌图像插入到字符串中。

ImageSpan is = new ImageSpan(context, R.drawable.arrow);

所以,你现在应该找到所有的情感角色并用ImageSpan s替换它们。

SpannableString text = new SpannableString("Your string here");

// Insert an ImageSpan into the string
text.setSpan(is, 5, 5 + 10, 0);

并将其应用于TextVeiw

textView.setText(text);