Calligraphy icon indicating copy to clipboard operation
Calligraphy copied to clipboard

Custom font not applied to Views contained in ViewPager

Open v-singhal opened this issue 9 years ago • 14 comments

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.

v-singhal avatar Nov 30 '16 16:11 v-singhal

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.

v-singhal avatar Dec 02 '16 03:12 v-singhal

@chrisjenx Any thoughts on this one? I'm about to check this...

njwandroid avatar Dec 20 '16 22:12 njwandroid

Not sure, this works for me, I would double check how you are getting the layout inflater

chrisjenx avatar Dec 20 '16 23:12 chrisjenx

@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.

njwandroid avatar Dec 20 '16 23:12 njwandroid

@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.

anoop44 avatar Mar 02 '17 08:03 anoop44

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 .

chrisjenx avatar Mar 02 '17 11:03 chrisjenx

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 avatar Mar 21 '17 22:03 redevill

@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.

anoop44 avatar Mar 22 '17 04:03 anoop44

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?

redevill avatar Mar 27 '17 16:03 redevill

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 avatar Mar 27 '17 16:03 redevill

@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

anoop44 avatar Mar 28 '17 06:03 anoop44

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 avatar Mar 28 '17 06:03 chrisjenx

@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.

anoop44 avatar Mar 28 '17 06:03 anoop44

Thanks guys, that makes sense

redevill avatar Mar 30 '17 01:03 redevill