我有这样的文字。
package de.majed.warehouse;
public class Box {
// The properties of the Box
private int Length, Width, Height;
private String id;
public Box() {
}
// To set the new properties values.
public Box(int newLength, int newWidth, int newHeight, String newID) {
setLength(newLength);
setWidth(newWidth);
setHeight(newHeight);
setID(newID);
}
public Box(Box newWidth) {
}
public int getLength() {
return Length;
}
public int getWidth() {
return Width;
}
public int getHeight() {
return Height;
}
public String getID() {
return id;
}
private void setLength(int newLength) {
Length = newLength;
}
private void setWidth(int newWidth) {
Width = newWidth;
}
private void setHeight(int newHeight) {
Height = newHeight;
}
private void setID(String newID) {
id = newID;
}
@Override
// To get the list of the new added boxes with their properties values.
public String toString() {
return "Box ID: " + getID() + " (L: " + getLength() + " - W: " + getWidth() + " - H: " + getHeight() + ")";
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (!(obj instanceof Box))
return false;
Box b = (Box) obj;
if (b == null)
return false;
if (this.id == null)
return b.id == null;
return this.id.equals(b.getID());
}
}
。
“\ u {1F603}”此文本必须显示为表情符号,但无法在Textview或AppCompatTextview中显示。有些表情符号表现得很像心,但微笑或生气没有表现出来。
我的项目中有很多textview。我如何以最简单的方式解决这个问题。
感谢您的任何建议。
答案 0 :(得分:2)
Emoji Compatibility来自支持库。
build.gradle
ext {
version = '27.1.1'
}
dependencies {
...
implementation "com.android.support:support-emoji-bundled:$version"
}
MyApplication
public class MyApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
EmojiCompat.init(new BundledEmojiCompatConfig(getApplicationContext()));
}
}
Manifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".MyApplication" // reference to my application for init needed.
android:theme="@style/AppTheme">
// other activities definition..
</application>
将表情符号设置为我的TextView
或AppCompatTextview
// Regular TextView without EmojiCompat support; you have to manually process the text
final TextView regularTextView = findViewById(R.id.textview);
EmojiCompat.get().registerInitCallback(new InitCallback(regularTextView));
InitCallback
private static class InitCallback extends EmojiCompat.InitCallback {
private final WeakReference<TextView> mRegularTextViewRef;
InitCallback(TextView regularTextView) {
mRegularTextViewRef = new WeakReference<>(regularTextView);
}
@Override
public void onInitialized() {
final TextView regularTextView = mRegularTextViewRef.get();
if (regularTextView != null) {
final EmojiCompat compat = EmojiCompat.get();
regularTextView.setText(compat.process("Neutral face \uD83D\uDE10"));
}
}
}
答案 1 :(得分:1)
您可以将这些库中的任何一个用于表情符号。我们也是这样做的。
https://android-arsenal.com/details/1/4366
答案 2 :(得分:-1)
试试这个
StringEscapeUtils.unescapeJava(//your string with emoji//)