aaverin
06/08/2016, 6:16 AM@Component(modules = BindingModule.class)
public interface BindingComponent extends DataBindingComponent {
}
DataBindingUtil.setDefaultComponent(DaggerBindingComponent.builder().build())
2. Write your BindingAdapter as extension function on android view:
@BindingAdapter("bind:font")
fun TextView.setFont(fontName: String) {
val baseContext = context.applicationContext as BaseContext
val typeface = baseContext.applicationComponent.typefaceProvider().getTypeface(fontName)
setTypeface(typeface)
}
3. Put font into assets
folder and define paths
fonts.xml
<string name="font_path_freight_text_lfpro_book">fonts/freight_text_lfpro_book.ttf</string>
4. Use it on your view
<TextView
android:id="@+id/tv_section"
style="@style/TextStyle.Kicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:text="@{viewModel.section}"
android:textAllCaps="true"
app:font="@{@string/font_path_freight_text_lfpro_book}"
tools:text="Text" />