我正在使用带有星星、太阳等字符的自定义字体。
我知道他们的 charcode 到这个字体。
我使用以下代码设置 TextView 字体:
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyTextView(Context context) {
super(context);
init();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/myFont.ttf");
setTypeface(tf ,1);
}}
有没有办法,因为我知道他们的字符代码,可以直接在 strings.xml 中以编程方式使用这些特定字符?
最佳答案
您可以在 java 中通过 4 位十六进制代码引用字符:
String someString = "\u2776"
或者在资源中:
<string name="some_string_name">\u2776</string>
(2776是❶在默认字体中的代码)
关于android - 使用charcode android检索自定义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35059053/