Reputation: 121
I'm a complete beginner to Android Studio, I'd like to know how to import new fonts(more precisely: Roboto and Pacifico font families)
Upvotes: 9
Views: 22477
Reputation: 1293
To use external fonts, first download the font in .tff format Google font- Roboto
Add the font asset folder as shown in the image below
After the font asset folder is created, copy and paste the downloaded .tff font into the "font" folder. (make sure the name is formatted well. )
Reference the font in your theme.xml or any layout using the android:fontFamily="@font/splashfont" property.
This is how you do it in a theme.xml file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.FishPott" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/color_black_level_1</item>
<item name="colorPrimaryVariant">@color/color_black_level_2</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/color_black_level_1</item>
<item name="colorSecondaryVariant">@color/color_black_level_2</item>
<item name="colorOnSecondary">@color/color_white_level_1</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:fontFamily">@font/robotoregular</item>
</style>
This is how you do it in a textview
<com.google.android.material.textview.MaterialTextView
android:id="@+id/activity_start_fp_MaterialTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:fontFamily="@font/splashfont"
android:gravity="center"
android:text="MyText"
android:textColor="@color/color_black_level_1"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activity_start_logo_ShapeableImageView" />
Upvotes: 5
Reputation: 382
It's easy.
more fonts
BONUS: If you would like to style EVERYTHING with text in your application with chosen font, just add <item name="android:fontfamily">@font/fontnamehere</item>
into your styles.xml
file.
Upvotes: 13
Reputation: 1165
For setting the font of your step there are some simple steps.
1.select File>New>Folder>Assets Folder
2.click finish
3.right click on assets and create a folder called fonts
4.put your font file in assets > fonts
5.then code to change your font(or create a new theme using that font.)
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/anyFont.ttf");
//and then use the typeface for changing the font using `textView.setTypeface(tf)`
Upvotes: 5
Reputation: 314
If you want to use these font for your android studio ide then download and install the fonts and change android studio code text font.
If you want to use font for your created android application then you have to put all .ttf files inside asset folder of the app. Please google that how to create asset folder and how to use custom font in your created application
Upvotes: -3