[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4177":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":14,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":20,"defaultBranch":21,"hasWiki":19,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":16,"starSnapshotCount":16,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},4177,"Calligraphy","chrisjenx\u002FCalligraphy","chrisjenx","Custom fonts in Android the easy way...","",null,"Java",8530,1075,1,82,0,40.1,"Apache License 2.0",true,false,"master",[],"2026-06-12 02:01:00","# This version of Calligraphy has reached its end-of-life and is no longer maintained. Please migrate to [Calligraphy 3](https:\u002F\u002Fgithub.com\u002FInflationX\u002FCalligraphy)!\n\nCalligraphy\n===========\n\n[![Android Arsenal](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FAndroid%20Arsenal-Calligraphy-blue.svg?style=flat)](http:\u002F\u002Fandroid-arsenal.com\u002Fdetails\u002F1\u002F163)\n\nCustom fonts in Android an OK way.\n\nAre you fed up of Custom Views to set fonts? Or traversing the ViewTree to find TextViews? Yeah me too.\n\n![alt text](https:\u002F\u002Fgithub.com\u002Fchrisjenx\u002FCalligraphy\u002Fraw\u002Fmaster\u002Fscreenshot.png \"ScreenShot Of Font Samples\")\n\n## Getting started\n\n### Dependency\n\nInclude the dependency [Download (.aar)](http:\u002F\u002Fsearch.maven.org\u002Fremotecontent?filepath=uk\u002Fco\u002Fchrisjenx\u002Fcalligraphy\u002F2.3.0\u002Fcalligraphy-2.3.0.aar) :\n\n```groovy\ndependencies {\n    compile 'uk.co.chrisjenx:calligraphy:2.3.0'\n}\n```\n### Add Fonts\n\nAdd your custom fonts to `assets\u002F`. All font definitions are relative to this path.\n\nAssuming that you are using Gradle you should create the assets directory under `src\u002Fmain\u002F` in your project directory if it does not already exist.\nAs it's popular to use multi-project build with Gradle the path is usually `app\u002Fsrc\u002Fmain\u002Fassets\u002F`, where `app` is the project name.\n\nYou might consider creating a `fonts\u002F` subdirectory in the assets directory (as in examples).\n\n### Usage\n\n```xml\n\u003CTextView fontPath=\"fonts\u002FMyFont.ttf\"\u002F>\n``` \n**Note: The missing namespace, this __IS__ intentional.**\n\n### Installation\n\nDefine your default font using `CalligraphyConfig`, in your `Application` class in the `#onCreate()` method.\n\n```java\n@Override\npublic void onCreate() {\n    super.onCreate();\n    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()\n                            .setDefaultFontPath(\"fonts\u002FRoboto-RobotoRegular.ttf\")\n                            .setFontAttrId(R.attr.fontPath)\n                            .build()\n            );\n    \u002F\u002F....\n}\n```\n\n_Note: You don't need to define `CalligraphyConfig` but the library will apply\nno default font and use the default attribute of `R.attr.fontPath`._\n\n### Inject into Context\n\nWrap the `Activity` Context:\n\n```java\n@Override\nprotected void attachBaseContext(Context newBase) {\n    super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));\n}\n```\n\n_You're good to go!_\n\n\n## Usage\n\n### Custom font per TextView\n\n```xml\n\u003CTextView\n    android:text=\"@string\u002Fhello_world\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    fontPath=\"fonts\u002FRoboto-Bold.ttf\"\u002F>\n```\n\n_Note: Popular IDE's (Android Studio, IntelliJ) will likely mark this as an error despite being correct. You may want to add `tools:ignore=\"MissingPrefix\"` to either the View itself or its parent ViewGroup to avoid this. You'll need to add the tools namespace to have access to this \"ignore\" attribute. `xmlns:tools=\"\nhttp:\u002F\u002Fschemas.android.com\u002Ftools\"`. See https:\u002F\u002Fcode.google.com\u002Fp\u002Fandroid\u002Fissues\u002Fdetail?id=65176._\n\n### Custom font in TextAppearance\n\n\n```xml\n\u003Cstyle name=\"TextAppearance.FontPath\" parent=\"android:TextAppearance\">\n    \u003C!-- Custom Attr-->\n    \u003Citem name=\"fontPath\">fonts\u002FRobotoCondensed-Regular.ttf\u003C\u002Fitem>\n\u003C\u002Fstyle>\n```\n\n```xml\n\u003CTextView\n    android:text=\"@string\u002Fhello_world\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    android:textAppearance=\"@style\u002FTextAppearance.FontPath\"\u002F>\n\n```\n\n### Custom font in Styles\n\n\n```xml\n\u003Cstyle name=\"TextViewCustomFont\">\n    \u003Citem name=\"fontPath\">fonts\u002FRobotoCondensed-Regular.ttf\u003C\u002Fitem>\n\u003C\u002Fstyle>\n```\n\n### Custom font defined in Theme\n\n```xml\n\u003Cstyle name=\"AppTheme\" parent=\"android:Theme.Holo.Light.DarkActionBar\">\n    \u003Citem name=\"android:textViewStyle\">@style\u002FAppTheme.Widget.TextView\u003C\u002Fitem>\n\u003C\u002Fstyle>\n\n\u003Cstyle name=\"AppTheme.Widget\"\u002F>\n\n\u003Cstyle name=\"AppTheme.Widget.TextView\" parent=\"android:Widget.Holo.Light.TextView\">\n    \u003Citem name=\"fontPath\">fonts\u002FRoboto-ThinItalic.ttf\u003C\u002Fitem>\n\u003C\u002Fstyle>\n```\n\n\n# FAQ\n\n### Font Resolution \n\nThe `CalligraphyFactory` looks for the font in a pretty specific order, for the _most part_ it's\n very similar to how the Android framework resolves attributes.\n \n1. `View` xml - attr defined here will always take priority.\n2. `Style` xml - attr defined here is checked next.\n3. `TextAppearance` xml - attr is checked next, the only caveat to this is **IF** you have a font \n defined in the `Style` and a `TextAttribute` defined in the `View` the `Style` attribute is picked first!\n4. `Theme` - if defined this is used.\n5. `Default` - if defined in the `CalligraphyConfig` this is used of none of the above are found \n**OR** if one of the above returns an invalid font. \n\n### Why *not* piggyback off of fontFamily attribute?\n\nWe originally did, but it conflicted with users wanting to actually use that attribute, you now \nhave to define a custom attribute.\n\n### Why no jar?\n\nWe needed to ship a custom ID with Calligraphy to improve the Font Injection flow. This\nunfortunately means that it has to be an `aar`. But you're using Gradle now anyway right?\n\n### Multiple Typeface's per TextView \u002F Spannables\n\nIt is possible to use multiple Typefaces inside a `TextView`, this isn't new concept to Android.\n\nThis _could_ be achieved using something like the following code.\n\n```java\nSpannableStringBuilder sBuilder = new SpannableStringBuilder();\nsBuilder.append(\"Hello!\") \u002F\u002F Bold this\n        .append(\"I use Calligraphy\"); \u002F\u002F Default TextView font.\n\u002F\u002F Create the Typeface you want to apply to certain text\nCalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(getAssets(), \"fonts\u002FRoboto-Bold.ttf\"));\n\u002F\u002F Apply typeface to the Spannable 0 - 6 \"Hello!\" This can of course by dynamic.\nsBuilder.setSpan(typefaceSpan, 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);\nsetText(sBuilder, TextView.BufferType.SPANNABLE);\n```\nOf course this is just an example. Your mileage may vary.\n\n### Exceptions \u002F Pitfalls\n\nTo our knowledge (try: `grep -r -e \"void set[^(]*(Typeface \" \u003Candroid source dir>`) there are two standard Android widgets that have multiple methods to set typefaces. They are:\n\n - android.support.v7.widget.SwitchCompat\n - android.widget.Switch\n\nBoth have a method called `setSwitchTypeface` that sets the typeface within the switch (e.g. on\u002Foff, yes\u002Fno). `SetTypeface` sets the typeface of the label. You will need to create your own subclass that overrides `setTypeface` and calls both `super.setTypeface` and `super.setSwitchTypeface`.\n\n\n\n\n\n# Collaborators\n\n- [@mironov-nsk](https:\u002F\u002Fgithub.com\u002Fmironov-nsk)\n- [@Roman Zhilich](https:\u002F\u002Fgithub.com\u002FRomanZhilich)\n- [@Smuldr](https:\u002F\u002Fgithub.com\u002FSmuldr)\n- [@Codebutler](https:\u002F\u002Fgithub.com\u002Fcodebutler)\n- [@loganj](https:\u002F\u002Fgithub.com\u002Floganj)\n- [@dlew](https:\u002F\u002Fgithub.com\u002Fdlew)\n- [@ansman](https:\u002F\u002Fgithub.com\u002Fansman)\n\n# Note\n\nThis library was created because it is currently not possible to declare a custom font in XML files in Android.\n\nIf you feel this should be possible to do, please star [this issue](https:\u002F\u002Fcode.google.com\u002Fp\u002Fandroid\u002Fissues\u002Fdetail?id=88945) on the official Android bug tracker.\n\n# Licence\n\n    Copyright 2013 Christopher Jenkins\n    \n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n        http:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0\n    \n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[![Badge](http:\u002F\u002Fwww.libtastic.com\u002Fstatic\u002Fosbadges\u002F79.png)](http:\u002F\u002Fwww.libtastic.com\u002Ftechnology\u002F79\u002F)\n","Calligraphy 是一个简化了 Android 应用中自定义字体设置的库。它通过提供一套简单易用的 API，使得开发者可以轻松地为整个应用或特定视图设置自定义字体，而无需创建自定义视图或手动遍历视图树来更改 TextView 的字体。该库支持直接在 XML 中指定字体路径，并且允许通过配置 CalligraphyConfig 来设置默认字体，从而在整个应用程序范围内统一字体风格。适用于需要快速集成自定义字体但又不想增加额外复杂性的 Android 项目。不过需要注意的是，当前版本已不再维护，建议迁移到更新版本的 Calligraphy 3 上。",2,"2026-06-11 02:58:52","top_language"]