2015-05-26 45 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);