Open pratikbutani opened 7 years ago
Hi, i am using databinding too. I dont get this issue. Did you init the lib the right way in the parent activity?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setFontAttrId(R.attr.fontPath)
.build()
);
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
@af-abe Thanks for reply, How did you have used in Fragment. Can you post your Fragment class.
As I mentioned, If I use
orderListBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_order_list, container, false);
this one to get View in fragment then its not applying styles.
@pratikbutani in general i used it like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_measure, container, false);
mBinding = DataBindingUtil.bind(view);
...
return view;
}
but your way also workes for me. tested with 'uk.co.chrisjenx:calligraphy:2.2.0'
@af-abe I dont know whats the problem actually but I am not getting actual font after changing fragment after navigation from NavigationView.
@pratikbutani did you try this?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(fragment_order_list, container, false);
orderListBinding = DataBindingUtil.bind(view);
...
return view;
}
@af-abe Yes I tried that code too but its not working for me.
@pratikbutani can you post more full examples of your setup as there is not enough to go off on here. Thanks.
How to use this function on a fragment !
@Override protected void attachBaseContext(Context newBase) { // Set Default Font super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); }
Can you guyz provide more information ! Its not enough to move on !
This is only applied to the Activity. Fragments extend from the Activity. No need to do anything else.
On Sat, 8 Apr 2017 at 19:21 Deshar Sunil notifications@github.com wrote:
How to use this function on a fragment !
@Override https://github.com/Override protected void attachBaseContext(Context newBase) { // Set Default Font super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); }
Can you guyz provide more information ! Its not enough to move on !
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/342#issuecomment-292736266, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsZL13DIret3PqBmoDLn0lcINxefvks5rt9AegaJpZM4Kfi14 .
@chrisjenx Still showing default font in fragments. Any idea?
How to use this function on a fragment !
@override protected void attachBaseContext(Context newBase) { // Set Default Font super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); }
Can you guyz provide more information ! Its not enough to move on !
How did you solve this?
Did you override this in the Activity NOT the Application?
@chrisjenx Yes did it like above. And the class extends AppCompatActivity
@Override protected void attachBaseContext(Context newBase) { super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase)); }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
OK how do you inflate fragments (it shouldn't matter) but you might need to override the Activity inflater too if you inflate in xml
@chrisjenx Check below
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
LayoutInflater mInflater = getActivity().getLayoutInflater();
View rootView = mInflater.inflate(R.layout.activity_dashboard, null);
TextView userEmail = rootView.findViewById(R.id.user_email_ID);
return rootView;
}
Yeah don't do that, always use the inflater given to you, or at worse LayoutInflater.from(context)
.
You may need to override this in the activity too:
/*
Uncomment if you disable PrivateFactory injection. See CalligraphyConfig#disablePrivateFactoryInjection()
*/
// @Override
// @TargetApi(Build.VERSION_CODES.HONEYCOMB)
// public View onCreateView(View parent, String name, @NonNull Context context, @NonNull AttributeSet attrs) {
// return CalligraphyContextWrapper.onActivityCreateView(this, parent, super.onCreateView(parent, name, context, attrs), name, context, attrs);
// }
@chrisjenx I have added it on my activity, still, the fragment shows default font. And also I tried changing like below in my fragment.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_dashboard, container, false);
return rootView;
}
I saw #29 Fragment Issue for loading fonts. May Its working fine with
LayoutInflater
likeLayoutInflater mInflater = getActivity().getLayoutInflater();
But I have used Data Binding Library with Fragment so I am inflating view like:
How can I solve it for Data Binding? Any Help please.