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);

Eliminar la animación entre actividades
Remove animation between activities


Por defecto, siempre que comenzamos o terminamos una actividad en Android, ésta se presenta con una animación. En general este comportamiento pasa desapercibido, pero puede haber casos en que no sea deseable. Por ejemplo, si queremos navegar entre actividades sin que el usuario se percate de ello.

Para desactivar la animación de una actividad tendremos que crear un nuevo Theme en nuestro fichero de estilos, ubicado en values/styles.xml.

<style name="noAnimTheme" parent="android:Theme">
        <item name="android:windowAnimationStyle">@null</item>
</style>

A continuación, sólo nos queda indicar en el manifest de la aplicación qué actividades usarán ese estilo.

<activity android:name="jvel.android.kidsgames.MainActivity"
          android:theme="@style/noAnimTheme" >
</activity>

Si en lugar de eliminar la animación, lo que queremos es utilizar una específica, sólo tenemos que indicar cuál en el elemento android:windowAnimationStyle del fichero de estilos.

By default, when we throw or we finish an activity on Android, it is begun with an animation. Most times this behaviour is good, but we can remove it if we need.

To remove the animation, we have to create a new Theme in styles, placed on values/styles.xml.

<style name="noAnimTheme" parent="android:Theme">
        <item name="android:windowAnimationStyle">@null</item>
</style>

Next, we have to change manifest file to tell what activities must use our new style.

<activity android:name="jvel.android.kidsgames.MainActivity"
          android:theme="@style/noAnimTheme" >
</activity>

If we don´t want to remove the animation, but change it, we just have to write the wanted one in android:windowAnimationStyle.