2015-07-12 84 views
3

我发现this answer这完全符合我的问题。但它不适合我。不知道为什么。也许我做错了什么。缅甸Android设备上的字体 - 整个应用程序

我完全复制了答案中的代码。所以在我的com.example.printhelper包中是Application.java一个FontsOverride.java文件。在水库/资产/字体我有Zawgyi_One.ttf字体。我有这条线:

<item name="android:typeface">serif</item> 

in 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

你为什么要设置字体“serif”而不是字体“Zawgyi One”或者其他字体的名称是什么? –

+0

@ Mike'Pomax'Kamermans看看我提到的问题。 FontsOverride.java覆盖默认字体。 'FontsOverride.setDefaultFont(this,“DEFAULT”,“Zawgyi_one.ttf”);' – kristyna

+0

值得把它放在你自己的帖子中。我无法确定您实际复制了哪些部分以及哪些部分不是您能添加代码到您的文章中(理想情况下,不仅仅是那一行,而是所有与您的问题相关的代码)? –

回答

0

我已经通过使用application/json; charset=utf-8修复它。我在我的android应用程序中查找问题,但它在发送方。

我正在使用Nette Framework,所以它没有听起来那么清楚。到底是哪需要更新的部分是:

JsonResponse($data, 'application/json; charset=utf-8')); 

是,在征求意见

,这不是一个问题,字体这是一个编码问题

。感谢@ njzk2的帮助。

相关问题