同时定义多个属性
如果给一个 View 添加多个属性, 并且这几个属性是相互影响的, 可以像下面这样定义;
| 1 2 3 4 |     @BindingAdapter({"background", "skin"})     public static void setViewBgStyle(Button view, String[] arrayId, int index) {     } | 
使用 res 中的数组资源
在 Data Binding 的 @{} 语句块内不能直接使用 @array, 需要替换为 @stringArray 或 @intArray
| Type | Normal link | Link in the expression | 
|---|---|---|
| String[] | @array | @stringArray | 
| int[] | @array | @intArray | 
| TypedArray | @array | @typedArray | 
| Animator | @animator | @animator | 
| StateListAnimator | @animator | @stateListAnimator | 
| Color int | @color | @color | 
| ColorStateList | @color | @colorStateList | 
下面的例子可以通过更改 "uite.skinType" 的值, 改变 Button 的背景图片, 可能可以用于 "换肤" ?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <resources>     <string-array name="left_m">         <item>"@drawable/m1"</item>         <item>"@drawable/m2"</item>         <item>"@drawable/m3"</item>         <item>"@drawable/m4"</item>     </string-array> </resources> <Button     ....     ....     app:background="@{@stringArray/left_m}"     app:skin="@{uite.skinType}" />     @BindingAdapter({"background", "skin"})     public static void setViewBgStyle(Button view, String[] arrayId, int index) {         int imageResource = view.getResources().getIdentifier(arrayId[index], null, view.getContext().getPackageName());         view.setBackgroundResource(imageResource);     } | 
 
	
0 Comments