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