Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android data binding - 'No resource identifier found for attribute'

My layout file:

<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> 

My binding adapter method:

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

The error I'm getting:

Error:(8) No resource identifier found for attribute 'fontName' in package 'com.example.databindingproject' 

Followed the tutorial from https://developer.android.com/tools/data-binding/guide.html . Any ideas of what I might be doing wrong?

like image 237
marius bardan Avatar asked Sep 04 '15 12:09

marius bardan


2 Answers

You must use the data binding syntax. It should be:

<TextView       android:text="@string/hello_world"       android:layout_width="wrap_content"       app:fontName='@{"Roboto-Regular.ttf"}'       android:layout_height="wrap_content"/> 
like image 142
George Mount Avatar answered Oct 06 '22 20:10

George Mount


This same error can also happen if you forget the closing curly brace:

android:text="@{viewModel.foo" 
like image 22
Wolfgang Avatar answered Oct 06 '22 18:10

Wolfgang