How do you use Calligraphy with TabLayout in Android Design Support Library for custom Font in xml? -


how use calligraphy apply custom font tablayout design support library please?

i have gotten work in java of answers seem refer to. (e.g. change font of tab text in android design support tablayout )

i'd prefer not make custom class, i'd use calligraphy. (https://github.com/chrisjenx/calligraphy )

  • if use custom style tabtextappearance can change textsize fontpath doesn't have effect.

thanks

there way use custom font in xml tablayout, it's little bit hacky. have provide own custom layout tabs , in layout can style textviews whatever like.

so need have setup:

public class mainactivity extends appcompatactivity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // viewpager , set it's pageradapter can display items     viewpager viewpager = (viewpager) findviewbyid(r.id.viewpager);     samplefragmentpageradapter pageradapter =          new samplefragmentpageradapter(getsupportfragmentmanager(), mainactivity.this);     viewpager.setadapter(pageradapter);      // give tablayout viewpager     tablayout tablayout = (tablayout) findviewbyid(r.id.sliding_tabs);     tablayout.setupwithviewpager(viewpager);      // iterate on tabs , set custom view     (int = 0; < tablayout.gettabcount(); i++) {         tablayout.tab tab = tablayout.gettabat(i);         tab.setcustomview(pageradapter.gettabview(i));     } }  //... } 

and pageradapter:

public class samplefragmentpageradapter extends fragmentpageradapter {      private context context;     private string tabtitles[] = new string[] { "tab1", "tab2" };      // ...      public view gettabview(int position) {         // given have custom layout in `res/layout/custom_tab.xml` textview         view v = layoutinflater.from(context).inflate(r.layout.custom_tab, null);         textview tv = (textview) v.findviewbyid(r.id.textview);         tv.settext(tabtitles[position]);         return v;     } } 

this custom_tab.xml:

<?xml version="1.0" encoding="utf-8"?> <textview xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/textview"     android:layout_width="match_parent"     android:layout_height="match_parent"     fontpath="fonts/customfont.otf"     tools:ignore="missingprefix" /> 

some things missing in code, think can fill in missing parts, gist of it. segment of blog post in references added addition of calligraphy. can take @ more details.

references:


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -