项目作者: MostafaTaghipour

项目描述 :
A font manager for Android to apply custom font to whole app, support multi font and change font at runtime
高级语言: Java
项目地址: git://github.com/MostafaTaghipour/FontManager.git
创建时间: 2019-02-03T17:46:07Z
项目社区:https://github.com/MostafaTaghipour/FontManager

开源协议:

下载


AndroidFontManager

iOS version is here

AndroidFontManger is a font manager for Android:

  • Support custom fonts
  • Apply to entire app
  • Support Multiple fonts
  • Change font at runtime
  • XML compatible
  • Code compatible
  • Supports various text appearances and font weights

custom font app

Requirements

  • Api 14+

Installation

Add JitPack to repositories in your project’s root build.gradle file:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Add the dependency to your module’s build.gradle file:

  1. dependencies {
  2. ...
  3. implementation 'com.github.MostafaTaghipour:fontmanager:${version}'
  4. }

Usage

  • Add your custom fonts to your project

fonts

  • Declare your fonts
  1. companion object {
  2. val exo: AppFont
  3. get() = AppFont.AppFontBuilder(1, "Exo", "fonts/exo/", "Exo-Regular", "ttf")
  4. .thin("Exo-Thin")
  5. .extraLight("Exo-ExtraLight")
  6. .light("Exo-Light")
  7. .regular("Exo-Regular")
  8. .medium("Exo-Medium")
  9. .semiBold("Exo-SemiBold")
  10. .bold("Exo-Bold")
  11. .extraBold("Exo-ExtraBold")
  12. .black("Exo-Black")
  13. .build()
  14. val taviraj: AppFont
  15. get() = AppFont.AppFontBuilder(2, "Taviraj", "fonts/taviraj/", "Taviraj-Regular", "ttf")
  16. .thin("Taviraj-Thin")
  17. .extraLight("Taviraj-ExtraLight")
  18. .light("Taviraj-Light")
  19. .regular("Taviraj-Regular")
  20. .medium("Taviraj-Medium")
  21. .semiBold("Taviraj-SemiBold")
  22. .bold("Taviraj-Bold")
  23. .extraBold("Taviraj-ExtraBold")
  24. .black("Taviraj-Black")
  25. .build()
  26. }
  • Wrap the Activity Context:
  1. override fun attachBaseContext(newBase: Context) {
  2. super.attachBaseContext(FontManager.wrapContext(newBase))
  3. }
  • Any time you need to change the font of the application use the following code
  1. FontManager.getInstance().currentFont = taviraj /* your desired font */
  • Thats it, enjoy it

TextAppearance

If you want use TextAppearances use the following code

XML

  1. <TextView
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:text="some text"
  5. android:textAppearance="@style/Text.Subhead" ></TextView>

Code

  1. FontManager.applyTextAppearanceToTextView(this,textView,R.style.Text_Bold)

Dependencies

Author

Mostafa Taghipour, mostafa@taghipour.me

License

AndroidFontManager is available under the MIT license. See the LICENSE file for more info.