lisawray / fontbinding Goto Github PK
View Code? Open in Web Editor NEWA full example of custom fonts in XML using data binding and including font caching.
License: Apache License 2.0
A full example of custom fonts in XML using data binding and including font caching.
License: Apache License 2.0
In my project I have both a TabLayout and a NavigationDrawer.
For the TabLayout
I inflate each tab as a custom layout. Like this:
LinearLayout appTab = (LinearLayout) LayoutInflater.from(activity).inflate(R.layout.custom_tab, null);
TextView appCardsTextView = (TextView) appTab.findViewById(R.id.tab_text);
appCardsTextView.setText("Application");
ImageView appCardsImageView = (ImageView) appTab.findViewById(R.id.tab_icon);
appCardsImageView.setImageResource(R.drawable.ic_application);
tabLayout.getTabAt(0).setCustomView(appTab);
custom_tab.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:id="@+id/tab_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/tab_text"
android:textColor="@color/white"
android:textSize="@dimen/tab_label"
android:text="testing"
app:font="@{`lato_hairline`}" <---- NOT WORKING!
/>
</LinearLayout>
</layout>
Is there a way to make it set the font in a situation like this through XML?
I found a workaround setting it through Java that I use for now:
appCardsTextView.setTypeface(FontCache.getInstance(appCardsTextView.getContext()).get("lato_hairline"));
But for XML it does not bind to the BindingAdapter
I have the same problem for my NavigationView
(sidebar) where I might have to get each item and set it through Java as well.
Thanks.
In the font cache the font is stored in the cache with the filename, but when this font is needed for another time the containsKey checks for the alias of the font.
Example:
fontFilename: MyFont-SemiBold.otf
stored in cache: fontFilename
checked: filename (myfont-semibold) [which is the alias]
I have many textview which needs common style with same font. I am curious about to know, does resources (such as style.xml, strings.xml) support the binding attributes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.