Last active
May 28, 2018 09:41
-
-
Save AhmadAyyaz1993/b4ba04fbd898c4a43b80835534118fac to your computer and use it in GitHub Desktop.
Custom TextView with custom Font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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