WilHall
WilHall

Reputation: 11994

Android: Adjusting EditText font size to fit text to one line

I am making an app that has two EditText views, txtOne which is used for input, and txtTwo which is used for output. txtOne is editable, and txtTwo is not.

I am looking for a simple way to scale the font size of the text in these two views so that it always fits within the view without wrapping to a new line.

I have found a few implementations of this using custom views extending TextView, but they aren't fit for an EditText view, or use android.graphics.Paint, which is not what I am looking for.

Is there any way to check to see when text in an EditText view is wrapping? If so, then it would be easy enough to do something like:

if(txtOne.isWrappingText()) {
    txtOne.setTextSize(txtOne.getTextSize() - 2);
}

Does anyone know of any way to detect this or an alternative solution?

Upvotes: 1

Views: 9153

Answers (1)

Knickedi
Knickedi

Reputation: 8787

I deleted my post

Basically the suggested code contained a TextWatcher for the EditText, this helped to answer the question. But the code itself was just wrong (I tested it meanwhile).

I suggest to read this question and answers because they adress the very same issue...

Upvotes: 3

Related Questions