我创建了简单的自定义视图,它扩展自TextView
,在 Android Studio 中我收到此警告
This custom view should extend android.support.v7.widget.AppCompatTextView instead
我不能使用clickable
属性,例如:
<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"/>
我收到此错误clickable
财产:
Error:(91, 46) Cannot find the setter for attribute 'android:clickable' with parameter type lambda on com.myapp.test.Widgets.FontAwesome.
我的自定义课程:
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);
}
}
我该如何解决这个问题?
UPDATE:如果您正在使用androidx 库而不是(旧版)v7 支持库(你现在应该这样做......),请改用这个:
import androidx.appcompat.widget.AppCompatTextView;
旧答案:(如果您还没有迁移到 androidx,仍然有用......)
这个自定义视图应该扩展
改为 android.support.v7.widget.AppCompatTextView
It's a Warning
,不是错误。
代替
public class FontAwesome extends TextView
你应该使用应用程序兼容文本视图 https://developer.android.com/reference/android/support/v7/widget/AppCompatTextView.html
public class FontAwesome extends AppCompatTextView
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)