I am trying to partial hide a number in a textview and when taping on an icon, it should display the full number. I receive a string of a specific lenght and need only show the last 4 digits.
so by default if I receive 123456789abc
-> I should display *******89abc
and when taping on an icon it shows 123456789abc
.
I used a 2 textview to do it one which contain the full text i.e. 123456789abc
and another textview with *******89abc
then I use the code below:
_binding?.viewIcon?.setOnClickListener {
if(strHidden) {
_binding?.viewIcon?.setImageDrawable(AppCompatResources.getDrawable(requireContext(), R.drawable.ic_hide))
_binding?.strPartial?.visibility = View.INVISIBLE
_binding?.strNumber?.visibility = View.VISIBLE
strHidden = false
} else {
_binding?.viewIcon?.setImageDrawable(AppCompatResources.getDrawable(requireContext(), R.drawable.ic_view))
_binding?.strPartial?.visibility = View.VISIBLE
_binding?.strNumber?.visibility = View.INVISIBLE
strHidden = true
}
}
I used the function below to create the string with hidden char.
private fun createHiddenStr(value: String) =
"*".repeat(value.length-4) + value.takeLast(4)
I was wondering if there is a way to use only one view and play with a mask instead which will be nicer that using 2 textview
Any idea?