Changing Text Size in Java

If you run the application on a device, you may have noticed that the timer text size is rather small on big screens, as shown in Figure 6.10.

Image

Figure 6.10 Application showing small timer text

You can fix this by changing the text size in Java. Follow these steps.

1. Open the res/values/strings.xml file. Add a new dimension node called timer_text_size and give it a value of 60:

<dimen name="timer_text_size" >60sp</dimen>

2. Open TimerActivity.java, and in the onCreate method, just after the set of findViewById calls, get the dimension using the getDimension() method. Set the counter text ...

Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.