Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android + Data Binding @style

While using the new data binding api, I found that you can't bind to the "style" attribute. Compiler complains that it can't find the style. However, if I simply set the style as is, it'll find it just fine. For example:

doesn't work:

style="@{TextUtils.isEmpty(row.getSubtitle()) ? @style/SubTitle : @style/Title}" 

works:

style="@style/SubTitle" 

Error:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Identifiers must have user defined types from the XML file. SubTitle is missing it file:/~/test/app/src/main/res/layout/row.xml loc:48:71 - 48:78 ****\ data binding error ****

like image 800
worked Avatar asked Aug 13 '15 05:08

worked


People also ask

What is data binding library in Android?

The Data Binding Library is an Android Jetpack library that allows you to bind UI components in your XML layouts to data sources in your app using a declarative format rather than programmatically, reducing boilerplate code. This codelab has been designed for those with some Android development experience.

What is data binding in Android jetpack?

Data Binding Library Part of Android Jetpack. The Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.

Is there a way to bind style to a view model?

viewModel.priceStyleResource is a MutableLiveData in my view model which is set with the style resource ID. You can also probably make a generic bindStyle binding adapter directly for the View class, but in that case the attribute items specifically for textviews ( textColor for example) will not get applied.

What is the use of binding components in Android textview?

<TextView android:text="@{viewmodel.userName}" />. Binding components in the layout file lets you remove many UI framework calls in your activities, making them simpler and easier to maintain. This can also improve your app's performance and help prevent memory leaks and null pointer exceptions.


1 Answers

The data binding unfortunately is not supported for styles: https://code.google.com/p/android-developer-preview/issues/detail?id=2613

like image 117
bwhite Avatar answered Oct 05 '22 01:10

bwhite