Skip to content

Instantly share code, notes, and snippets.

@donnfelker
Created April 1, 2011 14:12
Show Gist options
  • Save donnfelker/898205 to your computer and use it in GitHub Desktop.
Save donnfelker/898205 to your computer and use it in GitHub Desktop.
A custom Button that uses a custom font for all display.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_blue"
android:padding="0dp" >
<TextView
android:id="@+id/smokeTest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
/>
<com.qonqr.views.QButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/foobar"
android:text="This is a test"
android:background="@drawable/orange_button"
android:textSize="20pt"
android:textColor="#FFFFFF"
/>
</RelativeLayout>
package com.qonqr.views;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.Button;
public class QButton extends Button {
public QButton(Context context) {
super( context );
setFont();
}
public QButton(Context context, AttributeSet attrs) {
super( context, attrs );
setFont();
}
public QButton(Context context, AttributeSet attrs, int defStyle) {
super( context, attrs, defStyle );
setFont();
}
private void setFont() {
Typeface normal = Typeface.createFromAsset(getContext().getAssets(),"fonts/steelfish_rg.otf");
setTypeface( normal, Typeface.NORMAL );
Typeface bold = Typeface.createFromAsset( getContext().getAssets(), "fonts/steelfish_bd.otf" );
setTypeface( normal, Typeface.BOLD );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment