V
V
Vacxe2012-09-21 13:39:11
Android
Vacxe, 2012-09-21 13:39:11

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);
  }
    
}

How to add a preview to a component so that the graphical editor displays an analogue of the parent (TextView), and not the path to the component class?
Thanks for the help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LeoCcoder, 2012-09-21
@LeoCcoder

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 ...

V
Vacxe, 2012-09-21
@Vacxe

title_with_back.xml: Typeface.createFromAsset() is not supported.
Just a problem with him. Is it possible to display a view from the parent class in the editor?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question