Páginas

Personalizar la fuente de un texto
Customize text fonts

El tipo de letra a utilizar en un TextView se puede personalizar fácilmente en su definición xml, mediante la etiqueta android:typeface, que admite los valores sans, serif, monospace y normal.

<TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"      
        android:typeface="sans" />

Si queremos utilizar otro tipo de letra, necesitaremos el correspondiente fichero ttf. En equipos Windows podemos encontrar todos los que tengamos instalados en la carpeta Windows/Fonts. Para incorporarlo a nuestro aplicación Android simplemente tenemos que copiarlo en la carpeta assets, que está directamente en la raíz del proyecto.


En la imagen se puede ver la estructura para el proyecto en el que estoy trabajando actualmente, con la fuente Bubble Bath, que Rocco Pissani me ha cedido amablemente (¡Gracias!).

Una vez situada la fuente en su lugar, podemos utilizarla desde el código de cualquier actividad, y aplicarla a un TextView.

Typeface tf = Typeface.createFromAsset(this.getAssets(),
    "bubblebath.ttf");
textView.setTypeface(tf);
The font used in TextView elements can be customized in its xml definition, with the android:typeface tag, which can take sans, serif, monospace and normal values.

<TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"      
        android:typeface="sans" />

If we want to use another font, we need its ttf file. Under Windows we can find all that we have installed in our computer in the folder Windows/Fonts. To add it to our Android application, we just have to put it in assets folder, that is in the project root folder.


The previous picture shows the structure of the project I´m working actually, with the font Bubble Bath, that Rocco Pissani has yielded to me, nicely (Thanks!).

Once the font is placed in its location, we can use it in the code of any activity, and apply it to a TextView.

Typeface tf = Typeface.createFromAsset(this.getAssets(),
    "bubblebath.ttf");
textView.setTypeface(tf);

No hay comentarios:

Publicar un comentario