Jump to content

TextView et Spannable


fredm72

Recommended Posts

Bonsoir à tous,

Je continu mon apprentissage d'android et cette fois ci j'ai un problème de formatage de TextView.

J'ai 2 Textview dans un LinearLayout.

Pour essayer l'interface Spannable Je voudrais avoir le premier TextView en bleu souligné et le second en rouge.

Le code ressemble à ça (c'est un extrait de mon code):

TextView t1, t2;

Spannable sText, sText2;

t1= (TextView)this.findViewById(R.id.on);

t2= (TextView)this.findViewById(R.id.kun);

.....

t1.setText(on, TextView.BufferType.SPANNABLE);

Spannable sText = (Spannable) on.getText();

sText.setSpan(new ForegroundColorSpan(Color.BLUE), 0, on.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

sText.setSpan(new UnderlineSpan(), 0, on.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

.......

t2.setText(kun, TextView.BufferType.SPANNABLE);

Spannable sText2 = (Spannable) on.getText();

sText2.setSpan(new ForegroundColorSpan(Color.RED), 0, kun.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

sText2.setSpan(new UnderlineSpan(), 0, kun.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Le premier (t1) est correctement formater, quand au second rien ne change.

J'ai beau tourné le problème dans tout les sens rien n'y fait

J'ai mis en commentaire le formatage du premier TextView, au cas ou, pas de résultat non plus.

Dans mon xml, j'ai positionner android:bufferType="spannable"

Quelqu'un aurait il déjà eu le même soucis?

merci d'avance,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...