【问题标题】:Roboto light and Roboto bold in a TextViewTextView 中的 Roboto 灯和 Roboto 粗体
【发布时间】:2014-03-24 09:46:54
【问题描述】:

我可以像这样在 Android 2.3 上的同一个 TextView 中应用 Roboto light 和 Roboto bold 吗?

**user** has been publish a beez

**user** 是 Roboto 粗体,has been publish a beez 是 Roboto 浅色

【问题讨论】:

  • 您必须首先在您的资产/字体文件夹中下载ROBOTO font。然后按照post 中的说明访问该字体。最后将其与 Lokesh 的答案放在一起。

标签: java android textview spannablestring


【解决方案1】:

是的,你可以这样做..

String firstWord = "user";
String secondWord = "has been publish a beez";

// Create a new spannable with the two strings
Spannable spannable = new SpannableString(firstWord+secondWord);

// Set the custom typeface to span over a section of the spannable object
spannable.setSpan( new CustomTypefaceSpan("sans-serif",CUSTOM_TYPEFACE), 0, firstWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan( new CustomTypefaceSpan("sans-serif-light",SECOND_CUSTOM_TYPEFACE), firstWord.length(), firstWord.length() + secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

// Set the text of a textView with the spannable object
textView.setText( spannable );

您可以像这样从 Android 4.1+ 原生使用 Roboto:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed"

【讨论】:

猜你喜欢
  • 2017-01-17
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-02
  • 1970-01-01
  • 1970-01-01
  • 2017-02-04
相关资源
最近更新 更多