android - Change color Text from CustomTextView -


by default change textcolor programatically :

textview.settextcolor(color.red); 

i need have custom textview change typeface , color default, how can change textcolor customtextview class, here code.

public class customtextview extends textview {      public customtextview(context context, attributeset attrs, int defstyle) {         super(context, attrs, defstyle);         }      public customtextview(context context, attributeset attrs) {         super(context, attrs);      }      public customtextview(context context) {         super(context);       }  public void settypeface(typeface tf, int style) {      if(!isineditmode()) {         if (style == typeface.bold) {             super.settypeface(typeface.createfromasset(getcontext().getassets(), "fonts/lato-bold.ttf"));         } else if(style == typeface.italic){  // constant used set lato-light.             super.settypeface(typeface.createfromasset(getcontext().getassets(), "fonts/lato-light.ttf"));         }else {             super.settypeface(typeface.createfromasset(getcontext().getassets(), "fonts/lato-regular.ttf"));         }     } } 

the below code way set default text color , typeface.

public class customtextview extends textview { public customtextview(context context) {     super(context);     init(context); }  public customtextview(context context, attributeset attrs) {     super(context, attrs);     init(context); }  public customtextview(context context, attributeset attrs, int defstyleattr) {     super(context, attrs, defstyleattr);     init(context); }  private void init(context context) {     settypeface(typeface.createfromasset(context.getassets(),"fonts/lato-light.ttf"));     settextcolor(color.red); } } 

the init() method gets called every time text view gets created, , set typeface , color in that. can manipulate other variables want in there.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -