Skip to content

Instantly share code, notes, and snippets.

@AhmadAyyaz1993
Last active May 28, 2018 09:41
Show Gist options
  • Save AhmadAyyaz1993/b4ba04fbd898c4a43b80835534118fac to your computer and use it in GitHub Desktop.
Save AhmadAyyaz1993/b4ba04fbd898c4a43b80835534118fac to your computer and use it in GitHub Desktop.
Custom TextView with custom Font
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:background="@color/colorGreyBar"
>
<com.helpers.custom_ui.CustomFontTextView
android:id="@+id/tvTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textColor="@color/colorButtonRed"
android:text="Some text"
android:textSize="8sp"
/>
</android.support.design.widget.CoordinatorLayout>
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
public class CustomFontTextView extends TextView {
public static Typeface FONT_NAME;
public RegularProximaTextView(Context context) {
super(context);
if(FONT_NAME == null) FONT_NAME = Typeface.createFromAsset(context.getAssets(), "fonts/Mark Simonson - Proxima Nova Regular.otf");
this.setTypeface(FONT_NAME);
}
public RegularProximaTextView(Context context, AttributeSet attrs) {
super(context, attrs);
if(FONT_NAME == null) FONT_NAME = Typeface.createFromAsset(context.getAssets(), "fonts/Mark Simonson - Proxima Nova Regular.otf");
this.setTypeface(FONT_NAME);
}
public RegularProximaTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if(FONT_NAME == null) FONT_NAME = Typeface.createFromAsset(context.getAssets(), "fonts/Mark Simonson - Proxima Nova Regular.otf");
this.setTypeface(FONT_NAME);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment