Android Black Roboto font style

2.1k Views Asked by At

I would like to apply Black Roboto on a specific TextView. I defined a style, but I don't know how to set Black Roboto ?

In styles.xml file, I have this style:

<style name="IntroTitle">
    <item name="android:textSize">48sp</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textAllCaps">true</item>
</style>

in my 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"/>

Thanks by advance

3

There are 3 best solutions below

0
On BEST ANSWER

Thanks guys for your help.

The correct answer in my case for Black Roboto is:

    <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>

For more informations, check on: android-sdk/platforms/android-/data/fonts/system_fonts.xml

0
On

You need to set

android:fontFamily="sans-serif"

in order to use Roboto font in your TextView.

I think you meant bold by Black Roboto, so you'll need to add:

android:textStyle="bold"
0
On

Add the fontFamily attribute to your 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" gives regular Roboto while android:textStyle="bold" makes it bold/black.

If however, you have a Roboto-Black font file inside your assets folder and would like to apply it to your TextView, you're going to have to do it through code. For example:

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