How to import google fonts in Android Studio?

北城余情 提交于 2019-12-13 20:18:19

问题


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.

  1. Place a TextView.
  2. 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.
  3. In the little list, scroll all the way down till you see more fonts
  4. This will open up a dialog box where you can search from Google Fonts
  5. Search for the font you like with the search bar at the top
  6. Select your font.
  7. Select the style of the font you like (i.e. bold, normal, italic, etc)
  8. In the right pane, choose the radio button that says Add font to project
  9. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!