问题
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)
回答1:
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)`
回答2:
It's easy.
- Place a TextView.
- In the properties pane, select the font-family dropdown. If it isn't there, find the caret thingy (the > and click on it to expand the text attributes menu) Expand the font-family drop down.
- In the little list, scroll all the way down till you see
more fonts
- This will open up a dialog box where you can search from Google Fonts
- Search for the font you like with the search bar at the top
- Select your font.
- Select the style of the font you like (i.e. bold, normal, italic, etc)
- In the right pane, choose the radio button that says Add font to project
- Click okay. Now your TextView has the font you like!
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.
回答3:
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
来源:https://stackoverflow.com/questions/48305065/how-to-import-google-fonts-in-android-studio