2015-07-12 83 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的幫助。

相關問題