SORU
4 ŞUBAT 2011, Cuma


Android: bir dize parçası kullanarak TextView Boyama.() setText?

Üzerinden TextView bir görünüm metnini değiştirmek için arıyorum .(ayrıca metnin bir parçası boyama sırasında"") yöntemi (veya kalın, italik, şeffaf, vb.)setText ve geri kalanı değil. Örneğin:

title.setText("Your big island <b>ADVENTURE!</b>";

Yukarıdaki kodu doğru değil ama elde etmek istiyorum ne göstermek yardımcı olur biliyorum. Bunu nasıl yaparım?

CEVAP
4 ŞUBAT 2011, Cuma


spans kullanın.

Örnek:

final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");

// Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158)); 

// Span to make text bold
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); 

// Set the text color for first 4 characters
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 

// make them also bold
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 

yourTextView.setText(sb);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Brandon McCrary

    Brandon McCr

    15 Ocak 2012
  • LatinNinja99

    LatinNinja99

    28 EKİM 2011
  • Visual Life

    Visual Life

    3 Temmuz 2006