Answer the question
In order to leave comments, you need to log in
How to add Custom Components Preview?
I create my own custom component inherited from TextView
public class HelveticaTextView extends TextView {
public HelveticaTextView(Context context) {
super(context);
setFont(context);
}
public HelveticaTextView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
setFont(context, attributeSet);
}
public HelveticaTextView(Context context, AttributeSet attributeSet,
int defStyle) {
super(context, attributeSet, defStyle);
setFont(context, attributeSet);
}
private void setFont(Context context, AttributeSet attributeSet) {
final String androidns = "http://schemas.android.com/apk/res/android";
String textStyle = attributeSet.getAttributeValue(androidns,
"textStyle");
Typeface font = Typeface.createFromAsset(context.getAssets(),
"helvetica.otf");
if (textStyle != null) {
if (textStyle.equals("0x1"))
setTypeface(font, Typeface.BOLD);
else if (textStyle.equals("italic"))
setTypeface(font, Typeface.ITALIC);
else
setTypeface(font);
} else
setTypeface(font);
}
private void setFont(Context context) {
Typeface font = Typeface.createFromAsset(context.getAssets(),
"helvetica.otf");
setTypeface(font);
}
}
Answer the question
In order to leave comments, you need to log in
Update the SDK, if there is a place)
View the error log and find out what the visual editor swears at, should write why it was not possible to create an instance of your view ... I
just created a custom textview and it is displayed perfectly in the editor ... maybe you have problems loading the font ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question