Created
September 19, 2020 18:01
-
-
Save masoudkarimi/4cbf20baddbfd0db52aa658735a0facc to your computer and use it in GitHub Desktop.
Formatting DebitCard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun formatDebitCard(editable: Editable, paddingPx: Int) { | |
val textLength = editable.length | |
// first remove any previous span | |
val spans = editable.getSpans( | |
0, editable.length, | |
PaddingRightSpan::class.java | |
) | |
for (i in spans.indices) { | |
editable.removeSpan(spans[i]) | |
} | |
// adding spans | |
for (i in 0 until textLength) { | |
// 000`0` 000`0` 000`0` 0000 | |
if (i in arrayOf(3, 7, 11)) { | |
val marginSPan = | |
PaddingRightSpan(paddingPx) | |
editable.setSpan(marginSPan, i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment