如何在android中使用数据绑定显示类似(5%off)的文本?
我需要使用数据绑定在文本视图中显示文本(5% 折扣)。我的代码是
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_5"
android:text="@{@string/percentage_off(priceUIModel.discountOfferPercentage)}"
android:textAppearance="@style/Heading2Lines.Size12.Light"
android:textColor="@color/red_100"
app:visibility="@{priceUIModel.discountOfferPercentage !=null}" />
在 string.xml 中
<string name="percentage_off">%s\%% Off</string>
只需要在文本的前面和后面添加括号。我怎样才能修改这个string.xml?提前致谢。
I need to display text in text view (5% Off) using databinding. My code is
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_5"
android:text="@{@string/percentage_off(priceUIModel.discountOfferPercentage)}"
android:textAppearance="@style/Heading2Lines.Size12.Light"
android:textColor="@color/red_100"
app:visibility="@{priceUIModel.discountOfferPercentage !=null}" />
In string.xml
<string name="percentage_off">%s\%% Off</string>
Simply need to add brackets front and back of the text. How can I modify this string.xml? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
String.format()
命令:Use the
String.format()
command: