file layout của tôi:dữ liệu Android ràng buộc - 'Không có định danh tài nguyên tìm thấy cho thuộc tính'
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
app:fontName="Roboto-Regular.ttf"
android:layout_height="wrap_content"/>
</RelativeLayout>
phương pháp chuyển đổi ràng buộc của tôi:
public class FontBinding {
@BindingAdapter("bind:fontName")
public static void setFontName(TextView view, @NonNull String fontName) {
String fontPath = "/fonts/" + fontName;
Typeface typeface = Typeface.createFromAsset(view.getContext().getAssets(), fontPath);
view.setTypeface(typeface);
}
}
Các lỗi tôi nhận được:
Error:(8) No resource identifier found for attribute 'fontName' in package 'com.example.databindingproject'
Làm theo hướng dẫn từ https://developer.android.com/tools/data-binding/guide.html. Bất kỳ ý tưởng nào về những gì tôi có thể làm sai?
bạn đang cố gắng để thêm một nguồn tài nguyên phông chữ tùy chỉnh cho ứng dụng của bạn sử dụng không? – user5292387
Vị trí và cách setFontName được gọi? – Angudroid
Không quan trọng ngay bây giờ nếu tôi đang thử phông chữ tùy chỉnh hay không. Chỉ muốn xác định thuộc tính tùy chỉnh thông qua cơ chế ràng buộc dữ liệu Android. @Angudroid - kiểm tra liên kết từ bài đăng - tài liệu cho biết phương thức sẽ được hệ thống gọi. –