2012-09-13 11 views
5

Main.java:stili di carattere non funziona carattere personalizzato quando è impostato per la visualizzazione web

Main instanceMain = this; 
    String Dataz = FN.getHtmlData(instanceMain,"BMitra",20,(getResources().getString(R.string.matn2))); 
    btne.loadDataWithBaseURL("file:///android_asset/", Dataz, "text/html", "utf-8", null); 

FN.java:

public static String getHtmlData(Context context,String fontname,Integer fontsize, String data){ 
    String head = "<head><style type=\"text/css\">@font-face {font-family: 'MYFNT';src: url('"+fontname+".ttf');} body {text-align:justify;font-family: 'MYFNT';color: Black;}</style></head>"; 
    String htmlData= "<html>"+head+"<body dir=\"rtl\">"+data+"</body></html>" ; 
    return htmlData; 
} 

strings.xml:

<string name="matn2"> 
    <![CDATA[ 
    <html><body><b>سلام</b> non bold text . <b>english bold</b></body></html> 
    ]]> 
</string> 

ma grassetto tag non funziona e l'output è: سلام grassetto inglese. testo in grassetto non

dal modo in cui ho trovato some report issue


in un altro modo:

Main.java:

Main instanceMain = this; 
    String Dataz = FN.getHtmlData(instanceMain,getResources().getString(R.string.matn2))); 
    btne.loadDataWithBaseURL("file:///android_asset/", Dataz, "text/html", "utf-8", null); 

FN.java:

public static String getHtmlData(Context paramContext, String paramString) 
    { 
    return "<!DOCTYPE HTML><html lang=\"fa-ir\" dir=\"rtl\"><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"justified_textview.css\" />" + "</head>" + " <body>" + paramString + "</body></html>"; 
    } 

INGIUSTI d_textview.css (nella cartella assest):

/*@font-face { 
font-family:"MyFont"; 
src:url('file:///android_asset/BMITRA.TTF'); 
} 

@font-face { 
font-family:"MyFont"; 
src:url('file:///android_asset/BMITRABD.TTF'); 
font-weight: bold; 
}*/ 

@font-face { 
font-family: 'Conv_BMITRA'; 
src: url('file:///android_asset/BMITRA.ttf'); 
font-weight: normal; 
font-style: normal; 
} 

@font-face { 
font-family: 'Conv_BMITRA'; 
src: url('file:///android_asset/BMITRABD.ttf'); 
font-weight: bold; 
font-style: normal; 
} 


body { 
font-family:'Conv_BMITRA'; 
text-align:justify; 
line-height: 20pt; 
color: Black;  
} 

e matn2 (strings.xml):

<string name="matn"> 
    <![CDATA[ 
    م ولادت توی وب با سی اس اس 
    normal text 
    <b>ولایت بولد م bold text</b> 
    ]]> 
    </string> 

e ora il suo lavoro su Android 2.3.3 o 2.3.5, ma non funziona su android 4.0.x

+0

Hai provato a modificarlo tramite CSS? – Flo

+1

@Flo yes.and non working.by proposito, quando scrittura .boldClass {text-weight: bold} in css, aapt.exe ha smesso di funzionare e si è schiantato. e scrivi anche questo: b {peso del testo: grassetto} in css, non funziona più! –

risposta

5

Non è possibile, a causa di Webview piuttosto che il progresso del sistema operativo Android, è rotto. Se si imposta un font personalizzato per Webview, in alcuni dispositivi e sistemi operativi Android funziona e in alcuni altri no, sfortunatamente.

2

Mi sono imbattuto nello stesso problema su una pagina molto grande che stavo visualizzando. Prova a impostare l'attività con la webview su android:hardwareAccelerated="false" nel manifest.

+1

cosa è associato con la webview? puoi spiegare di più? –

+1

Non sono sicuro del modo in cui la visualizzazione Web viene eseguita dal disegno accelerato hardware, ma alcune funzioni non sono supportate dall'accelerazione hardware. Ecco maggiori informazioni al riguardo: [Android Hardware Acceleration] (http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html). Alcune delle funzioni che non sono supportate o che si sa che si comportano diversamente sono relative al disegno del testo. – Chris

Problemi correlati