Search code examples
androidkotlinandroid-edittext

How to get count of symbols which can fit editText without horizontal scrolling?


[enter image description here]

I have editText which scrolls horizontally. I want to decrease text size if text doesn't fit editText without scrolling. I tried use following condition:

var textSize = edtResult.textSize / resources.displayMetrics.scaledDensity

    if (edtResult.width >= cardView.width && textSize > 22.0)

but edtResult.width returns width without scrolling

So my question:

  1. How to get count of symbols which can fit editText without scrolling with current textSize?
  2. Or how to get editText's width with symbols which don't fit?

Solution

  • You could try using the autosize TextView feature (only available for API >= 26 if using TextView. For lower versions, use AppCompatTextView).