2015-05-26 46 views
2

我想在特定的TextView上应用Black Roboto。我定义了一种风格,但我不知道如何设置Black Roboto?Android Black Roboto字体样式

在styles.xml文件,我有这样的风格:

<style name="IntroTitle"> 
    <item name="android:textSize">48sp</item> 
    <item name="android:textStyle">normal</item> 
    <item name="android:textAllCaps">true</item> 
</style> 
在我layout.xml

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/title" 
    style="@style/IntroTitle" 
    android:textColor="@android:color/white" 
    android:text="@string/intro_title_screen_1"/> 

由于通过提前

+0

你有一个ttf文件的字体? – yrazlik

回答

2

谢谢你们的帮助。

在我来说,我黑色的Roboto正确的答案是:

<style name="IntroTitle"> 
     <item name="android:fontFamily">sans-serif-black</item> 
     <item name="android:textSize">30sp</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textAllCaps">true</item> 
    </style> 

欲了解更多信息,请查看:Android的SDK /平台/ android- /数据/字体/ system_fonts.xml

0

您需要设置

android:fontFamily="sans-serif" 

为了使用Ro boto字体在您的TextView

我想你的意思是由黑色的Roboto大胆的,所以你需要添加:

android:textStyle="bold" 
1

添加fontFamily中的属性到你的TextView

<TextView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/title" 
style="@style/IntroTitle" 
android:textColor="@android:color/white" 
android:text="@string/intro_title_screen_1" 
android:fontFamily="sans-serif" 
android:textStyle="bold"/> 

android:fontFamily="sans-serif"给正规的Roboto而android:textStyle="bold"使它粗体/黑色。

但是,如果您的资产文件夹内有一个Roboto-Black字体文件,并且想要将其应用于TextView,则必须通过代码完成此操作。例如:

Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Black.ttf"); 
yourTextView.setTypeface(type);