Calligraphy
Calligraphy copied to clipboard
Custom font not applied to Views contained in ViewPager
I am inflating views and not fragments in my ViewPager. Upon doing so, the custom fonts aren't being applied.
When the said views are used outside of the ViewPager, they work perfectly fine.
Not really sure as to cause of the issue.
Also I am using com.android.support:appcompat-v7:24.2.0, if that helps.
PS: Love the work on the lib.
Anu updates on this?
PS: If I add fragments in the view pager instead of views, it works fine but I want to avoid using fragments as they are heavy in comparison to views.
@chrisjenx Any thoughts on this one? I'm about to check this...
Not sure, this works for me, I would double check how you are getting the layout inflater
@v-singhal @chrisjenx Actually, works for me too, so perhaps this is useful for whoever searches next, and/or you could close this... at least default font works for me, I didn't try others yet.
@v-singhal @chrisjenx @njwandroid This issue depends on the Context used to get the LayoutInflater instance. In My PagerAdapter I was injecting Context via Dagger2 which was ApplicationContext, and I instantiated LayoutInflater in constructor using that Context and Calligraphy had no impact there. When I removed that instantiation and did it on the instantiateItem method like LayoutInflater.from(container.getContext()), Calligraphy was working as expected. Hope it helps to resolve the issue.
I'm writing a talk, quite literally on this now!
On Thu, Mar 2, 2017, 08:59 Anoop S S [email protected] wrote:
@v-singhal https://github.com/v-singhal @chrisjenx https://github.com/chrisjenx @njwandroid https://github.com/njwandroid This issue depends on the Context used to get the LayoutInflater instance. In My PagerAdapter I was injecting Context via Dagger2 which was ApplicationContext', and I instantiated LayoutInflater in constructor using thatContext' and Calligraphy had no impact there. When I removed that instantiation and did it on the instantiateItem method like LayoutInflater.from(container.getContext()), Calligraphy was working as expected. Hope it helps to resolve the issue.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/348#issuecomment-283595331, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsRIoHe-9Upj0oY7wIq-5EATexEpFks5rhoTugaJpZM4LAbBC .
Is it possible that something similar is happening when you setCustomView on the SupportActionBar? Because the fonts are not being applied for me in this case.
@redevill are you be setting custom view like this getSupportActionBar().setCustomView(View);. If yes check the Context you use in the LayoutInflater to inflate that custom view.
So, it seems I did not understand, in which activity I should place "super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));" The application was set up with a startup activity derived from another(EventListenerClass) that extended AppCompatActivity. So I placed it in the EventListener class. My logic was, that this class was the closest class to the activity base in the hierarchy of the app starting activity. This did not work. I moved it to another activity that was not part of the start up, but core to the app, and this appeared to work. Perhaps I don't understand the scope of the "context". Must the attachbasecontext potentially be placed in more than one activity?
With the above change, I did manage to have it work, at least for the activity in which it was placed. Did not yet check to see what the scope of the influence is in the application.
@redevill If you have multiple activities and you want calligraphy in every activity, best way to do it is create a base activity which all other activities extend and place the calligraphy attachBaseContext in theoncreate of base activity
You have to init Calligraphy in the Application class! Then attach to the base context in every activity.
On Tue, Mar 28, 2017, 07:25 Anoop S S [email protected] wrote:
@redevill https://github.com/redevill If you have multiple activities and you want calligraphy in every activity, best way to do it is create a base activity which all other activities extend and place the calligraphy initialization in theoncreate of base activity
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/348#issuecomment-289675478, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRscbCXjAHBaGmnm6ffHDorY9WXIuzks5rqKfigaJpZM4LAbBC .
@chrisjenx Sorry I phrased it wrongly. By initialising in oncreate of BaseActivity what i meant is to attach to base context. I will correct the previous comment
You have to init Calligraphy in the Application class! Then attach to the base context in every activity.
Thanks guys, that makes sense