2010-11-08 5 views

Répondre

3

Tout ce que vous avez besoin est de créer un fichier xml dans res/valeurs et écrire quelque chose comme ce qui suit:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="header"> 
     /** here goes the style */ 
    </style> 
</resources> 

Alors tous vos besoins est de passer généré R.style.header au constructeur TextAppearanceSpan.

+0

Mes onglets sont TextViews, j'ai donc fini par utiliser la classe Spannable pour appliquer le style. – Eno

2

Il est établi à http://developer.android.com/guide/appendix/faq/commontasks.html#selectingtext , regardez la deuxième manière en utilisant Spannable.

Plus précisément

// Get our EditText object. 
EditText vw = (EditText)findViewById(R.id.text); // or new etc 

// Set the EditText's text. 
vw.setText("Italic, highlighted, bold."); 

// Get the EditText's internal text storage 
Spannable str = vw.getText(); 

// Create our span sections, and assign a format to each. 
str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
Questions connexes