19

I`ll wish change the text size in run-time based in the old size.

How get a text size in SP (Scaled Pixel) directly from a TextView?

Something like:

textMove.setTextSize(textMove.getTextSPSize()  + sizeFontScale);
Zeus Monolitics
  • 812
  • 9
  • 19

2 Answers2

29

What about:

float px = editext.getTextSize();
float sp = px / getResources().getDisplayMetrics().scaledDensity;
t0m
  • 2,850
  • 27
  • 50
10

So... setTextSize(int) actually assumes Scaled Pixels. getTextSize() returns the actual pixels. If you want to increase by an amount of actual pixels then you can call getTextSize(), add whatever, then call setTextSize(TypedValue.COMPLEX_UNIT_PX, newValue). I guess I'm kind of wondering if you really want to do everything in Scaled Pixels.

dmon
  • 29,903
  • 7
  • 86
  • 95