复数在 xml 中不起作用

Plurals don't work in xml

我正在尝试在 TextInputEditText:

的错误文本中加载复数形式
<android.support.design.widget.TextInputEditText
    android:id="@+id/et_subject_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textCapWords"
    android:lines="1"
    android:maxLines="1"
    android:singleLine="true"
    android:text="@{ model.name }"
    android:hint="@string/hint_name"
    app:validateRegex='@{"^*\S{2}.*$"}'
    app:validateRegexMessage="@{@plurals/error_too_short(model.minNameLength)}"/>

但在我的应用程序中,它显示了我的字符串,但使用 %d 而不是 model.minNameLength 值。 app:validateRegex 是由 Data Binding Validator 库定义的属性。
我的复数形式:

<plurals name="error_too_short">
    <item quantity="one" >Too short, enter at least %d visible character.</item>
    <item quantity="other" >Too short, enter at least %d visible characters.</item>
</plurals>

怎么了?或者在 xml?
中有其他显示复数的方法吗 P.S。如果它很重要,我会使用数据绑定引擎 V2。

它应该是这样的:

<plurals name="recent_messages">
    <item quantity="zero">No Recent Messages</item>
    <item quantity="one">1 Recent Message</item>
    <item quantity="other">%1$d Recent Messages</item>
</plurals>

mContext.getResources().getQuantityString(R.plurals.recent_messages, count, count);

在官方Android docs:

When using the getQuantityString() method, you need to pass the count twice if your string includes string formatting with a number. For example, for the string %d songs found, the first count parameter selects the appropriate plural string and the second count parameter is inserted into the %d placeholder. If your plural strings do not include string formatting, you don't need to pass the third parameter to getQuantityString.

因此,当您希望 model.minNameLength 定义 select 的复数版本以及将其值插入字符串时,您应该提供两次。因此,databinding 表达式应该改为:

app:validateRegexMessage="@{@plurals/error_too_short(model.minNameLength, model.minNameLength)}"