【发布时间】:2017-04-06 05:23:06
【问题描述】:
我创建了从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);
}
}
我该如何解决这个问题?
【问题讨论】:
-
extend android.support.v7.widget.AppCompatTextView与 TextView 相同。 AppCompatTextView 用于为旧版 Android 的新功能提供向后兼容性。 -
thois 不是问题,你可以扩展任何你想要的。 Android Studio 只警告你 AppCompatTextView 更适合用于兼容性。
-
代码仍然会运行......这只是一个警告
-
是否启用数据绑定?
标签: android