Páginas

Customize text fonts

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

Remove animation between activities


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.