Coder Social home page Coder Social logo

sangupandi / fontbinding Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lisawray/fontbinding

0.0 1.0 0.0 2.67 MB

A full example of custom fonts in XML using data binding and including font caching.

License: Apache License 2.0

Java 100.00%

fontbinding's Introduction

fontbinding

Easy custom fonts in XML using data binding.

No setup required, no extra Java code, and no custom views.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:font="@{`alegreya`}"
    />

Drawing

This example includes a simple font cache that automatically loads names from your assets/fonts folder and lazy-loads typefaces. Just drag and drop font files and use them in XML by their normal or lowercase filenames (e.g. "Roboto-Italic" or "roboto-italic" for Roboto-Italic.otf). That's it!

###Data binding Make sure to use the data binding framework to inflate your layout.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DataBindingUtil.setContentView(this, R.layout.activity_main);
    }
}

More about data binding: http://developer.android.com/tools/data-binding/guide.html

###Custom naming You can set custom names for your fonts, but you don't have to.

FontCache.getInstance().addFont("alegreya", "Alegreya-Regular.ttf");

##Note: It's not currently possible to define custom attributes in styles using data binding. If you require this, check out Calligraphy by Chris Jenx.

fontbinding's People

Watchers

Sangu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.