废话不多说、直接上代码。
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView myTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myTextView = new TextView(this);
myTextView.setMovementMethod((LinkMovementMethod.getInstance()));
setEmojiToTextView();
setContentView(myTextView);
}
/**
* 1. Emoticons ( 1F601 - 1F64F )
* 2. Dingbats ( 2702 - 27B0 )
* 3. Transport and map symbols ( 1F680 - 1F6C0 )
* 4. Enclosed characters ( 24C2 - 1F251 )
* 5. Uncategorized
* 6a. Additional emoticons ( 1F600 - 1F636 )
* 6b. Additional transport and map symbols ( 1F681 - 1F6C5 )
* 6c. Other additional symbols ( 1F30D - 1F567 )
*/
private void setEmojiToTextView() {
setEmojiToTextView(0x1F601, 0x1F64F);
setEmojiToTextView(0x2702, 0x27B0);
setEmojiToTextView(0x1F680, 0x1F6C0);
setEmojiToTextView(0x1F681, 0x1F6C5);
setEmojiToTextView(0x1F30D, 0x1F567);
//setEmojiToTextView(0x24C2, 0x1F251);
}
private void setEmojiToTextView(int start, int end) {
int[] unicodeJoy = new int[end - start + 1];
for (int i = start ; i <= end ; i++) {
unicodeJoy[i - start] = i;
}
String emojiString = getEmojiStringByUnicode(unicodeJoy);
myTextView.append(emojiString);
myTextView.append("\n\n\n");
}
private String getEmojiStringByUnicode(int[] unicode) {
StringBuilder stringBuilder = new StringBuilder();
for (int code : unicode) {
stringBuilder.append(Character.toChars(code));
}
return stringBuilder.toString();
}
}
网友评论