AACustomFont是XML中轻巧的自定义字体粘合剂,直接在TextView , Button , EditText , RadioButton , CheckBox标签中。该库的目的是避免XML中自定义字体的自定义视图,并最大程度地减少Java代码以设置每个视图的字体。
您可以在从TextView延伸的任何视图中使用AACustomFont 。例如, TextView Button EditText RadioButton CheckBox

可以使用Maven,Gradle或手动安装AACustomFont 。
步骤1。将Jitpack存储库添加到您的构建文件
< repositories >
< repository >
< id >jitpack.io</ id >
< url >https://jitpack.io</ url >
</ repository >
</ repositories >步骤2。添加依赖关系
< dependency >
< groupId >com.github.EngrAhsanAli</ groupId >
< artifactId >AACustomFont</ artifactId >
< version >1.1</ version >
</ dependency >步骤1。将Jitpack存储库添加到您的构建文件
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
步骤2。添加依赖关系
dependencies {
compile 'com.github.EngrAhsanAli:AACustomFont:1.1'
}
如果您不希望使用上述依赖关系经理中的任何一个,则可以通过将Java文件夹中包含的文件添加到项目中,将AACustomFont集成到项目中。
您需要启用数据绑定,以便将自定义字体与您的视图绑定。在您的build.gradle中添加以下内容。
android {
dataBinding {
enabled = true
}
}您可以在资产/字体目录中添加字体文件。 AACustomFont将自动从该目录自动获取字体。字体文件可能具有.ttf或.otf扩展名。
您需要更改布局父标签以layout标签,然后将其余的标签放在该标签中。
< layout xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : app = " http://schemas.android.com/apk/res-auto "
xmlns : tools = " http://schemas.android.com/tools " >
<!-- Put the layouts here -->
</ layout >现在将您的字体设置为:
< TextView
<!-- other properties -->
app:font="@{`budidaya-italic`}" />请注意,字体名称将始终处于小写状态。如果未指定字体,它将在
app:font="@{``}中获取默认字体。
您需要绑定Java中的视图:
DataBindingUtil . setContentView ( this , R . layout . your_layout );
// Using LayoutInflator
DataBindingUtil . inflate ( inflater , R . layout . your_layout , this , true );您可以使用以下方法将别名设置为字体名称
AACustomFont.getInstance(this)
.setAlias("myfont", "Font-File.otf")
.setDefaultFontName("myfont");
您可以使用以下方法使用字体名称覆盖字体
// For all typefaces in given activity context with default font
AACustomFont.getInstance(this).overrideFonts(this);
// For all typefaces in given activity context with specified font
AACustomFont.getInstance(this).overrideFonts(this, "my_font");
// For all typefaces in given viewgroup with specified font
AACustomFont.overrideFonts(button, "myfont");
AACustomFont可根据MIT许可获得。有关更多信息,请参见许可证文件。
欢迎拉动请求!最佳贡献将包括替换或配置,用于在典型的应用程序生命周期期间已知的类/方法封锁主线程的方法。
我很想知道您是否在应用程序中使用AACustomFont ,请发送电子邮件给Engr。 Ahsan Ali