Android custom view should extend AppCompatTextView

I created simple custom view which that extended from TextView, in Android Studio i get this wanrning

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

and i can't use clickable propertise, for example:

   <com.myapp.test.Widgets.FontAwesome
       android:layout_width="60dp"
       android:layout_height="match_parent"
       android:layout_marginRight="5dp"
       android:background="?selectableItemBackground"
       android:gravity="center"
       android:clickable="@{()->presenter.clickOnSend()}"
       android:text="@string/font_icon_post_message"
       android:textColor="@color/gray_text_color"
       android:textSize="40sp"/>

i get this error for clickable propertise:

Error:(91, 46) Cannot find the setter for attribute 'android:clickable' with parameter type lambda on com.myapp.test.Widgets.FontAwesome. 

my custom class:

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class FontAwesome extends TextView {
    public FontAwesome(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

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

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

    private void init() {
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
                "fonts/fontawesome.ttf");
        setTypeface(tf);
    }
}

how can i resolve this problem?

Answers


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

Need Your Help

How to remove event listener in Chrome extension

javascript events event-handling google-chrome-extension

I am trying to remove the onRequest listener added by chrome.extension.onRequest.addListener after a request is made, like this:

handle json request in PHP

php ajax json request mime-types

When making an ajax call, when contentType is set to application/json instead of the default x-www-form-urlencoded, server side (in PHP) can't get the post parameters.