Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Custom Auto TextView in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 587
    Comment on it

    If you want to create custom auto textview components you have to extends widget class like TextView,Button etc.Its very simple create your own class and write constructor corresponding to the constructor of the base class.

  • CustomFont class
    import android.content.Context;
    import android.graphics.Typeface;
    import android.util.AttributeSet;
    import android.widget.TextView;
    
    public class CustomFont extends TextView{
    
        Context context;
        String ttfName="";
    
        String TAG = getClass().getName();
    
        public CustomFont(Context context, AttributeSet attrs) 
        {
            super(context, attrs);
            this.context = context;
    
            init();
        }
        private void init() {
            Typeface font = Typeface.createFromAsset(context.getAssets(), "lucon.ttf");
            setTypeface(font);
    
    
        }
    
        @Override
        public void setTypeface(Typeface tf) {
            super.setTypeface(tf);
        }
    }
    

  • crate xml file and replace your with following code :
  • <packagename.classname
                android:id="@+id/customfont"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hello"
                android:textColor="@color/text_color"
                android:textSize="@dimen/text_size;
    
Comment on it

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: