Android のデータ バインディングは現在、次の参照リソースをサポートしているようです (データバインディングガイドによる@arrayと@color) :@int@dimen@string@BindingAdapter
例えば:
レイアウト/web_view.xml
<WebView
app:htmlTextColor="@{@color/colorText}"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Bindings.java
@BindingAdapter({"bind:htmlTextColor"})
public static void setHtml(WebView webView, int textColor) {
// binding logic
}
しかし、テーマとスタイル?android:attr/textColorPrimaryでは、参照よりも属性リソースを使用することがよくあり@colorます。そのような場合、バインディング"@{}"構文はどのようになりますか? 現在、これが私が機能させる方法ですが、もっと良い方法があるでしょうか?
レイアウト/web_view.xml
<WebView
app:htmlTextColor="@{android.R.attr.textColorPrimary}"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Bindings.java
@BindingAdapter({"bind:htmlTextColor"})
public static void setHtml(WebView webView, int textColorAttr) {
// binding logic
}