XML, , Eclipse ADT XML-. , .ttf .
textview:
public class TypefacedTextView extends TextView
{
public TypefacedTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
if (isInEditMode())
{
return;
}
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);
styledAttrs.recycle();
if (fontName != null)
{
Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontName);
setTypeface(typeface);
}
}
}
, TypefacedTextView XML-, XML Android XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:your_namespace="http://schemas.android.com/apk/res/com.example.app"
... />
And use your TypefacedTextView as plain text in XML, but with your own tag, remembering to set the font:
<com.example.app.TypefacedTextView
android:id="@+id/list_item_entry_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:textColor="#FF787878"
your_namespace:typeface="Roboto-Regular.ttf" />
See my blog for more information:
http://polwarthlimited.com/2013/05/android-typefaces-including-a-custom-font/
source
share