chrisjenx / Calligraphy

Custom fonts in Android the easy way...
Apache License 2.0
8.59k stars 1.09k forks source link

not supported in 'tabTextAppearance' attribute in TabLayout #383

Open rahul01 opened 7 years ago

rahul01 commented 7 years ago

Want to use with tabTextAppearance attribute

like this:

in styles:

    <style name="TextAppearance.RobotoMedium" parent="android:TextAppearance">
        <!-- Custom Attr-->
        <item name="fontPath">fonts/Roboto-Medium.ttf</item>
    </style>

in layout:

 <android.support.design.widget.TabLayout
               ...
               ...
               app:tabTextAppearance="@style/TextAppearance.RobotoMedium"
 />

don't want to to this: ##http://stackoverflow.com/a/39252162/1529129

xeon90 commented 7 years ago

I just found why, because Tab is added after calligraphy injected and apply font, and not sure TabLayout not referencing the typeface when adding Tab If your tab is added dynamically like my case, this is the only solution i have, you can refer my code, it is improved and cleaner version from your link, applicable for activity, but dynamic view like recycler view need to apply for the newly added view.

Picture for your reference, u can see the 3rd tab is not apply typeface after i call apply root view

    protected void apply(ViewGroup vg)
    {
        Typeface type = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/oxygen_light.ttf");

        for(int i = 0; i < vg.getChildCount(); ++i)
        {
            View v = vg.getChildAt(i);
            if(v instanceof TextView)
                ((TextView) v).setTypeface(type);
            else if(v instanceof ViewGroup)
                apply((ViewGroup) v);
        }
    }

You can do this in activity root view

    setContentView(R.layout.activity_main);
    apply((ViewGroup) findViewById(android.R.id.content));

screenshot_20170422-231059

rahul01 commented 7 years ago

@xeon90 : works great, however still looking for its support from the library.

ali73 commented 7 years ago

@xeon90 works great. This solution works for tabitems added in xml file too. :+1:

adrianojpn commented 5 years ago

Esta solução funciona muito. Muito obrigado.

dfavaro commented 5 years ago

Hi, issue still present. Any solution?