Setting Up The Style Or Typeface Of A Custom View Which Contains Text, Like Default Textview?
I`m implementing a custom view which contains text, and the text will be drawn in onDraw. My problem is, I wish my text will looks like those in the TextView objects, but I`m not q
Solution 1:
publicclassCustomTextextendsTextView {
publicCustomText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stubTypefacetypeface= Typeface.createFromAsset(context.getAssets(),
"fonts/your_font.ttf");
setTypeface(typeface);
}
publicCustomText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stubTypefacetypeface= Typeface.createFromAsset(context.getAssets(),
"fonts/fonts/your_font.ttf");
setTypeface(typeface);
}
publicCustomText(Context context) {
super(context);
// TODO Auto-generated constructor stubTypefacetypeface= Typeface.createFromAsset(context.getAssets(),
"fonts/fonts/your_font.ttf");
setTypeface(typeface);
}
}
Now use the CustomText in your class/xml.
Hope this will help you.
Post a Comment for "Setting Up The Style Or Typeface Of A Custom View Which Contains Text, Like Default Textview?"