I am trying to toggle between the old way of displaying a password with the following databinding expression:
android:password="@{isMyFlagTrue}"
However when I try to use the inputType
in lieu of the now deprecated password attribute, I can't seem to successfully set the password type. I have tried:
android:inputType="@{isMyFlagTrue? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)}"
But this made no effect on the inputType of the EditText
view. Even when I try to set it directly to the invisible variety it is still visible.
Any suggestions?
Data Binding Library Part of Android Jetpack. Stay organized with collections Save and categorize content based on your preferences. The Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.
Databinding is really faster compared to findViewById and setText . Not only performance, It is also much faster and maintainable for mid, full-scale projects. As a side note, benefits include: performance.
Two-way data binding is nothing but updating the data source if there are any changes in the layout and vice versa. Two-way data binding is not applicable for all the views in Android. For example, using two-way data binding in EditText makes sense because users can update the data in the view.
You can set input type use data-binding like
<EditText
...
android:inputType='@{condition ? (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD) : InputType.TYPE_CLASS_TEXT }'
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With