Featured post

Marshmallow Features Point by Point

Android Runtime (“ART”) Improved application performance and lower memory overhead for faster  multi-tasking. Battery Doze...

Wednesday 7 May 2014

Custom View

Java Class
========

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class FontTextView extends TextView {


    public FontTextView(Context context) {
      super(context);
      Typeface face=Typeface.createFromAsset(context.getAssets(), "Helvetica_Neue.ttf"); 
      this.setTypeface(face); 
    }

    public FontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
     Typeface face=Typeface.createFromAsset(context.getAssets(), "Helvetica_Neue.ttf"); 
  this.setTypeface(face); 
    }

    public FontTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
     Typeface face=Typeface.createFromAsset(context.getAssets(), "Helvetica_Neue.ttf"); 
  this.setTypeface(face); 
    }

    protected void onDraw (Canvas canvas) {
        super.onDraw(canvas);
        
       
    }

}
Xml layout
             <com.util.FontTextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/accountInfoText"
                    android:textColor="#727272"
                    android:textSize="18dp" />
                 
http://stackoverflow.com/questions/9477336/how-to-make-custom-textview/9477393#9477393

No comments:

Post a Comment