Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import android.content.Context
  2. import android.text.InputType
  3. import android.util.AttributeSet
  4. import com.example.hijaunesia.R
  5.  
  6. internal class OTPChildEditText : androidx.appcompat.widget.AppCompatEditText {
  7.  
  8. constructor(context: Context) : super(context) {
  9. init(context)
  10. }
  11.  
  12. constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
  13. init(context)
  14. }
  15.  
  16. constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
  17. init(context)
  18. }
  19.  
  20. private fun init(context: Context) {
  21. isCursorVisible = false
  22. setTextColor(context.resources.getColor(R.color.transparent))
  23. setBackgroundDrawable(null)
  24. inputType = InputType.TYPE_CLASS_NUMBER
  25. setSelectAllOnFocus(false)
  26. setTextIsSelectable(false)
  27. }
  28.  
  29. public override fun onSelectionChanged(start: Int, end: Int) {
  30.  
  31. val text = text
  32. text?.let { text ->
  33. if (start != text.length || end != text.length) {
  34. setSelection(text.length, text.length)
  35. return
  36. }
  37. }
  38.  
  39. super.onSelectionChanged(start, end)
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement