0

I was wondering if there is a way that I can make my string font size auto adjustable in android meaning if the word size is too long for space, the font becomes smaller by itself. As it is shown in the picture attached my buttons are made using Java and not XML so the function needs to be in Java. Also, the minimum supported Android version is API 21 so the new AutoSizing feature in Android won't work.

Masum
  • 790
  • 6
  • 25
Aria
  • 33
  • 4
  • How about this? : https://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds – Stanley Ko Mar 05 '19 at 04:56
  • Possible duplicate of [Auto Scale TextView Text to Fit within Bounds](https://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds) – Stanley Ko Mar 05 '19 at 04:56
  • You fixed the height and width of the button programmitically, right? – amitava Mar 05 '19 at 10:52

1 Answers1

0

Something similar to this should work.

if(view.getText().length()>18){
        view.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.smallTextsize));
    }else
    if(view.getText().length()>10){
        view.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.mediumTextsize));
    }else {
        view.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.largeTextsize));
    }
Enividmk
  • 41
  • 1
  • 4