我发现this answer完全适合我的问题。但它对我不起作用。不知道为什么。也许我做错了什么。
我完全复制了答案中的代码。所以在我的com.example.printhelper包中是Application.java的一个FontsOverride.java文件。在res / assets / fonts中我有Zawgyi_One.ttf字体。我有这条线:
<item name="android:typeface">serif</item>
在theme.xml中。
一些缅甸单词存储在我的数据库(UTF-8)中,我通过http get通过json获取它们。
但我仍在(ñöõ)½ºýüþºû±ý(ôð)þ±à èºî
而不是缅甸字母上看到EditText
。
我做错了吗?我使用Android Studio编辑器。
CODE: Application.java
package com.example.printhelper;
public final class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "Zawgyi_One.ttf");
FontsOverride.setDefaultFont(this, "DEFAULT_BOLD", "Zawgyi_One.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "Zawgyi_One.ttf");
FontsOverride.setDefaultFont(this, "SERIF", "Zawgyi_One.ttf");
FontsOverride.setDefaultFont(this, "SANS_SERIF", "Zawgyi_One.ttf");
}
}
FontsOverride.java
public final class FontsOverride {
public static void setDefaultFont(Context context, String staticTypefaceFieldName, String fontAssetName) {
final Typeface regular = Typeface.createFromAsset(context.getAssets(), fontAssetName);
replaceFont(staticTypefaceFieldName, regular);
}
protected static void replaceFont(String staticTypefaceFieldName, final Typeface newTypeface) {
try {
final Field staticField = Typeface.class.getDeclaredField(staticTypefaceFieldName);
staticField.setAccessible(true);
staticField.set(null, newTypeface);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
注意:我想覆盖所有TextView和 EditText
仍然没有答案。我想我的应用程序中有一些东西阻止了字体,但我不知道是什么以及为什么。我的应用程序中有几个主题可供用户选择。所有样式都在styles.xml和themes.xml中。所有主题都来自同一个父母。可以仅为父级声明字体样式,对吧?
编辑:为json做好准备 - 我使用AsyncTask
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httpget,responseHandler);
编辑2:字符串转换
我将响应转换为十六进制
HttpGet httpget = new HttpGet(url);
httpget.setHeader("Content-type", "application/json; charset=utf-8");;
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httpget,responseHandler);
byte[] array = httpclient.execute(httpget,responseHandler).getBytes();
StringBuffer hexString = new StringBuffer();
for (byte b : array) {
int intVal = b & 0xff;
if (intVal < 0x10)
hexString.append("0");
hexString.append(Integer.toHexString(intVal));
}
System.out.println(hexString);
这就是它抛出的东西
7b22766965776572735f6964223a33352c22766965776572735f66697273746e616d65223a224b41222c22766965776572735f6c6173746e616d65223a22204b412053455420333528437573746f6d657220c382c2bdc383c2a2c382c2b6c383c2bdc382c2a6c383c2a0c383c2a8c383c2adc382c2b6c383c2a0c382c2a5c383c2bdc383c2bcc382c2bcc383c28cc383c2bd29222c22766965776572735f7374726565746e616d65223a22c383c282c382c2bac383c2bbc382c2b1c383c2bd20c383c2b4c383c2b3c383c2bec382c2bfc383c2a3c382c2bcc383c2a2c382c2bac382c2a3c3a2c280c29cc382c2bdc383c2a020c382c2bdc382c2bac383c2bdc383c2bcc382c2bfc383c2aec382c2bbc383c2bd20c383c2b2222c22766965776572735f686f7573656e756d223a6e756c6c2c22766965776572735f63697479223a6e756c6c2c22766965776572735f706f7374636f6465223a6e756c6c2c22766965776572735f6372656174696f6e5f74696d65223a7b2264617465223a22323031322d31312d31382031373a30313a30362e303030303030222c2274696d657a6f6e655f74797065223a332c2274696d657a6f6e65223a22417369612f52616e676f6f6e227d2c22766965776572735f69735f616374697665223a312c22766965776572735f6e6f7465223a6e756c6c2c22766965776572735f736d617274636172645f6964223a313435303030303033332c22766965776572735f736574746f70626f785f6964223a6e756c6c2c22766965776572735f636f6e74726163745f6e756d626572223a22222c22766965776572735f656d61696c223a6e756c6c2c22766965776572735f70686f6e656e756d223a3231313535342c22766965776572735f68705f6e756d626572223a6e756c6c2c22766965776572735f6d61726974616c5f737461747573223a2273696e676c65222c22766965776572735f646174655f6f665f61637469766174696f6e223a6e756c6c2c22766965776572735f616765223a302c22766965776572735f6f636375706174696f6e223a6e756c6c2c22766965776572735f6e69665f63696e223a6e756c6c2c22766965776572735f7a6f6e65223a6e756c6c2c22766965776572735f67656e646572223a226d616c65222c22766965776572735f70686f6e656e756d32223a6e756c6c2c22766965776572735f637265617465645f75736572735f6964223a6e756c6c2c22766965776572735f6163746976617465645f75736572735f6964223a6e756c6c2c22766965776572735f656469746564223a6e756c6c2c22766965776572735f6469766973696f6e735f6964223a6e756c6c2c22766965776572735f746f776e73686970735f6964223a6e756c6c2c22766965776572735f6465616c6572735f6964223a6e756c6c2c22766965776572735f626f75717565745f6578706972655f64617465223a7b2264617465223a22323031312d31312d31312030303a30303a30302e303030303030222c2274696d657a6f6e655f74797065223a332c2274696d657a6f6e65223a22417369612f52616e676f6f6e227d2c22766965776572735f6f70656e65645f7469636b6574223a302c22766965776572735f736574746f70626f785f726570616972223a302c22766965776572735f656469745f74696d65223a6e756c6c2c22766965776572735f656469745f75736572735f6964223a6e756c6c2c22766965776572735f73656c6663617265223a7b2264617465223a222d303030312d31312d33302030303a30303a30302e303030303030222c2274696d657a6f6e655f74797065223a332c2274696d657a6f6e65223a22417369612f52616e676f6f6e227d2c22766965776572735f6269727468646179223a6e756c6c7d
Here您可以将十六进制转换为字符串。
这是否意味着问题出在服务器上?
答案 0 :(得分:0)
我已经使用application/json; charset=utf-8
修复了它。我在我的Android应用程序中寻找问题,但它是在发送方。
我正在使用Nette Framework,所以它听起来并不那么清晰。确切地说,需要更新的部分是:
JsonResponse($data, 'application/json; charset=utf-8'));
是的,来自评论
这不是编码问题的字体问题
。感谢@ njzk2的帮助。