Được TopGit lập chỉ mục từ metadata GitHub: chrisjenx/Calligraphy có 8.5k sao, viết chủ yếu bằng Java. Custom fonts in Android the easy way...
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Add your custom fonts to assets/. All font definitions are relative to this path.
Assuming that you are using Gradle you should create the assets directory under src/main/ in your project directory if it does not already exist.
As it's popular to use multi-project build with Gradle the path is usually app/src/main/assets/, where app is the project name.
You might consider creating a fonts/ subdirectory in the assets directory (as in examples).
Usage
<TextView fontPath="fonts/MyFont.ttf"/>
Note: The missing namespace, this IS intentional.
Installation
Define your default font using CalligraphyConfig, in your Application class in the #onCreate() method.
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=" http://schemas.android.com/tools". See https://code.google.com/p/android/issues/detail?id=65176.
The CalligraphyFactory looks for the font in a pretty specific order, for the most part it's
very similar to how the Android framework resolves attributes.
View xml - attr defined here will always take priority.
Style xml - attr defined here is checked next.
TextAppearance xml - attr is checked next, the only caveat to this is IF you have a font
defined in the Style and a TextAttribute defined in the View the Style attribute is picked first!
Theme - if defined this is used.
Default - if defined in the CalligraphyConfig this is used of none of the above are found
OR if one of the above returns an invalid font.
Why not piggyback off of fontFamily attribute?
We originally did, but it conflicted with users wanting to actually use that attribute, you now
have to define a custom attribute.
Why no jar?
We needed to ship a custom ID with Calligraphy to improve the Font Injection flow. This
unfortunately means that it has to be an aar. But you're using Gradle now anyway right?
Multiple Typeface's per TextView / Spannables
It is possible to use multiple Typefaces inside a TextView, this isn't new concept to Android.
This could be achieved using something like the following code.
SpannableStringBuilder sBuilder = new SpannableStringBuilder();
sBuilder.append("Hello!") // Bold this
.append("I use Calligraphy"); // Default TextView font.
// Create the Typeface you want to apply to certain text
CalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(getAssets(), "fonts/Roboto-Bold.ttf"));
// Apply typeface to the Spannable 0 - 6 "Hello!" This can of course by dynamic.
sBuilder.setSpan(typefaceSpan, 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(sBuilder, TextView.BufferType.SPANNABLE);
Of course this is just an example. Your mileage may vary.
Exceptions / Pitfalls
To our knowledge (try: grep -r -e "void set[^(]*(Typeface " <android source dir>) there are two standard Android widgets that have multiple methods to set typefaces. They are:
android.support.v7.widget.SwitchCompat
android.widget.Switch
Both have a method called setSwitchTypeface that sets the typeface within the switch (e.g. on/off, yes/no). 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.
Collaborators
@mironov-nsk
@Roman Zhilich
@Smuldr
@Codebutler
@loganj
@dlew
@ansman
Note
This library was created because it is currently not possible to declare a custom font in XML files in Android.
If you feel this should be possible to do, please star this issue on the official Android bug tracker.
Licence
Copyright 2013 Christopher Jenkins
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
chrisjenx/Calligraphy có 8.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/chrisjenx/Calligraphy. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
chrisjenx/Calligraphy có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho chrisjenx/Calligraphy. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
chrisjenx/Calligraphy còn đang phát triển không?
Commit gần nhất trên chrisjenx/Calligraphy là 2.6 năm trước (theo timestamp GitHub). Repo có 1.1k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
chrisjenx/Calligraphy viết bằng ngôn ngữ gì?
chrisjenx/Calligraphy chủ yếu viết bằng Java. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về chrisjenx/Calligraphy ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/chrisjenx/Calligraphy là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Calligraphy có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về Calligraphy.