I want to make certain part of my text to bold whose value is set using DataBinding with ViewModel.
For e.g
If you are selected, you will pay $160 for your pair.
I am using strings resources
<string name="product_price">If you are selected, you will have to pay $%d for your pair.</string>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing_xlarge"
android:layout_marginStart="@dimen/spacing_xlarge"
android:layout_marginBottom="@dimen/spacing_small"
android:text="@{@string/product_price(productPrice)}"
android:textColor="@color/button_tertiary"
android:visibility="@{productPrice > 0}"
style="@style/Body.Small"
/>
Currently passing product price using ViewModel with Binding by setting binding.setProductPrice(Object.getPrice())
I know the following solutions : But want to try using DataBinding
- Using Html Text - But don't want to use it in code.
- Using Different TextView in Horizontal Style. Setting styles as bold for that Product Price. - Really Bad Practice
- Using SpannableString - But don't want to use it in code.
But all of the above solutions are workaround.
Question ::
Want to try DataBinding feature which can be used to style certain part of string. Just like SpannableString
Manipulate String in the Layout file using DataBinding