Skip to content

Fontize is an Android library that enables multi-font selection functionality to beautify your app.

License

Notifications You must be signed in to change notification settings

gouravkhunger/Fontize

Repository files navigation

Fontize Android Library

Fontize Android Library Licence Fontize Android Library Licence Fontize Android Library Licence Fontize Android Library Stars Fontize Android Library Forks Fontize Android Library Issues
Built with ❤︎ by Gourav Khunger

Fontize is an Android library, written in kotlin, that enables your android app have multiple fonts for your TextViews and switch between them in a jiffy!

A quick demo:

Fontize Android Library Demo GIF

Adding Fontize to your project

Include jitpack in your root build.gradle file.

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

And add it's dependency to your app level build.gradle file:

dependencies {
    implementation "com.github.gouravkhunger:Fontize:1.0.1"
}

Sync the project and you'll have imported Fontize successfully.

Start using Fontize

Make sure you have all your fonts in the res/font/ directory. Support for font files in the assets folder will ship soon!

Rename all the TextViews or AppCompatTextViews in your project to com.github.gouravkhunger.fontize.FontizeTextView - You don't have to change anything else, and the view would still perform the same :)

Before:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/switch_font_to"
    android:layout_marginTop="150dp"
    android:textSize="18sp"/>

After:

<com.github.gouravkhunger.fontize.FontizeTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/switch_font_to"
    android:layout_marginTop="150dp"
    android:textSize="18sp"/>

To set up a default font for the TextViews that should load at the startup, add this line to the beginning of your launcher activity:

Fontize(this).setDefaultFont(R.font.exo_2) // replace with the font you desire

To update the font for all of your app, simple call this line from anywhere inside the app:

Fontize(this).updateFont(R.font.zen_old_mincho) // updates fontFamily of all the TextViews throughout app

Note:

  • this must be an Acitvity or Application context.
  • This requires recreation of the activity, which can be done by recreate(), or prompt the user to relaunch the app to make the changes take effect.

How does it work?

Fontize saves the resource ID of the font you provide to SharedPreferences. It extends AppCompatTextView class to inherit all the properties of a TextView, but overrides the default inflating behaviour. It applies the typography when the view is inflated.

Only TextViews?

I'll try to add support for other views in the future. Contributions are always welcome.

🛡 License

This project is MIT Licensed.

MIT License

Copyright (c) 2021 Gourav Khunger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

There are some fonts used in the demo app, their licenses are available here.


Fontize needs a ⭐ from you =)

About

Fontize is an Android library that enables multi-font selection functionality to beautify your app.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors 3

  •  
  •  
  •  

Languages