android - How do i use a custom font in a fragment layout? -


*edit

i think has android 5.0.2. tried activity, , gives me same error.

so i'm new navigation drawer , fragments. works fine , want have textview custom font. works method below, doesn't.

public class homefragment extends fragment {  public homefragment(){}  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {      // use everytime normal layouts, fragment layout doesnt work     textview txt = (textview) findviewbyid(r.id.textviewhome);       typeface font = typeface.createfromasset(getassets(), "impact.ttf");       txt.settypeface(font);         view rootview = inflater.inflate(r.layout.fragment_home, container, false);      return rootview;   } } 

the errors are:

the method getassets() undefined type homefragment method findviewbyid(int) undefined type homefragment  

as i'm new android programming, want solution , want understand why it's wrong. highly appreciated!

you need change few things. need inflate view first before getting children, , activity assets:

public class homefragment extends fragment {    public homefragment(){}  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {       view rootview = inflater.inflate(r.layout.fragment_home, container, false);     textview txt = (textview) rootview.findviewbyid(r.id.textviewhome);       typeface font = typeface.createfromasset(getactivity().getassets(), "impact.ttf");       txt.settypeface(font);       return rootview;   } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -