2012-09-13 6 views
5

Main.java:estilos de fuente no funciona cuando se establece fuente personalizada para vistaweb

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> 

pero negrita la etiqueta no funciona y la salida es: سلام inglés negrita. no el texto en negrita

por la manera que he encontrado some report issue


de otra manera:

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>"; 
    } 

justificado d_textview.css (en la carpeta 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;  
} 

y matn2 (strings.xml):

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

y ahora su trabajo en Android 2.3.3 o 2.3.5, pero no trabajando en android 4.0.x

+0

¿Has intentado estilizarlo a través de css? – Flo

+1

@Flo yes.and not working.by por cierto, cuando escriba .boldClass {text-weight: bold} en css, aapt.exe ha dejado de funcionar y se ha bloqueado. e incluso escriba esto: b {text-weight: bold} en css, ¡no funciona de nuevo! –

Respuesta

5

No es posible, debido a Webview en lugar del progreso del sistema operativo Android, está roto. Si configura una fuente personalizada para Webview, en algunos dispositivos y Android OS funciona, y en algunos otros no, desafortunadamente.

2

Me encontré con el mismo problema en una página muy grande que estaba mostrando. Intente configurar la actividad con la vista web en android:hardwareAccelerated="false" en el manifiesto.

+1

¿qué está asociado con la vista web? ¿Puedes explicarme mas? –

+1

No estoy seguro específicamente de cómo la vista web se ve afectada por el dibujo acelerado por hardware, pero hay algunas funciones que no son compatibles con la aceleración de hardware. Aquí hay más información sobre eso: [Android Hardware Acceleration] (http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html). Algunas de las funciones que no son compatibles o se sabe que se comportan de manera diferente son el dibujo de texto relacionado. – Chris

Cuestiones relacionadas