Android custom view should extend AppCompatTextView

UPDATE: If you're using androidx libraries instead of the (legacy) v7 support libraries (which you ought to do so now...), please use this instead:

import androidx.appcompat.widget.AppCompatTextView;

OLD ANSWER: (still useful if you've not migrated to androidx yet...)

This custom view should extend android.support.v7.widget.AppCompatTextView instead

It's a Warning, not an Error.

Instead of

public class FontAwesome extends TextView

You should use AppCompatTextView

public class FontAwesome extends AppCompatTextView 

I was with a similar problem but it's fixed. It is probably you only see the result on execution time the first time. I didn't test to rebuild project again without launch the app.

 import android.content.Context;
 import android.graphics.Color;
 import android.support.v7.widget.AppCompatTextView;
 import android.util.AttributeSet;

 public class CustomTxtView extends AppCompatTextView {

    public CustomTxtView(Context context) {
        super(context);
        init();
    }

    public CustomTxtView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomTxtView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        setText("Hello World");
        setTextColor(Color.RED);
    }

}

Tags:

Android