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?
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); } }
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With