Before start Code we require to our font file means like over ttf file into asset folder in android studio.
After it you require to decide where you want to set font like Textview,EditText,Button as per your rquirement.
Like following Demo.
I have font file "HelveticaLight_0.ttf" which is stored in asset directory.
Hear i am creating Class for Button.
Then after use this class where you require button component.
After it you require to decide where you want to set font like Textview,EditText,Button as per your rquirement.
Like following Demo.
I have font file "HelveticaLight_0.ttf" which is stored in asset directory.
Hear i am creating Class for Button.
package com.dhaval.solanki; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Typeface; import android.os.Build; import android.util.AttributeSet; import android.widget.Button; import android.widget.TextView; public class HelveticaLight_0Button extends Button { public HelveticaLight_0Button(Context context) { super(context); init(); } public HelveticaLight_0Button(Context context, AttributeSet attrs) { super(context, attrs); init(); } public HelveticaLight_0Button(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public HelveticaLight_0Button(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(); } private void init() { Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "HelveticaLight_0.ttf"); setTypeface(tf); }}
Then after use this class where you require button component.
<com.tristate.truepal.customview.HelveticaLight_0Button
android:id="@+id/btnDone"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.tristate.truepal.customview.HelveticaLight_0Button>
1 comment:
Very Helpful to me ,Thanks.
Post a Comment