1

Is possible to change dynamically the size of the text of an EditText when the text is too long and readjust it to fit within the bounds?

azurefrog
  • 9,994
  • 7
  • 36
  • 51

2 Answers2

1

I believe you should create a custom TextView. Check out @speedplane soulution : How to adjust text font size to fit textview

Community
  • 1
  • 1
Behzad Bahmanyar
  • 5,696
  • 4
  • 29
  • 38
0
EditText editText = (EditText) findViewById(R.id.editText);
editText.addTextChangedListener(new TextWatcher()
{
    public void afterTextChanged(Editable s) {}
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    public void onTextChanged(CharSequence s, int start, int before, int count)
    {
        if (editText.getText().toString().length() > 15)
        {
            editText.setTextSize(10)
        }
});

I've not tested this but that should generally work.

  • But in some devices (with a bigger screen), the editText can containsmore than 15 chars..... instead, smaller screen devices can contain less than 15 chars – Gabriele Marcozzi Sep 04 '15 at 19:35