Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not supported in 'tabTextAppearance' attribute in TabLayout #383

Open
rahul01 opened this issue Apr 21, 2017 · 5 comments
Open

not supported in 'tabTextAppearance' attribute in TabLayout #383

rahul01 opened this issue Apr 21, 2017 · 5 comments

Comments

@rahul01
Copy link

rahul01 commented Apr 21, 2017

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
Copy link

xeon90 commented Apr 22, 2017

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
Copy link
Author

rahul01 commented Apr 25, 2017

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

@ali73
Copy link

ali73 commented Jul 22, 2017

@xeon90 works great.
This solution works for tabitems added in xml file too.
👍

@adrianojpn
Copy link

adrianojpn commented Feb 22, 2019

Esta solução funciona muito. Muito obrigado.

@dfavaro
Copy link

dfavaro commented Jun 7, 2019

Hi, issue still present. Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants