Instead of using this following line for each textview:
android:textSize="40sp"
Am I able to replace 40sp with a variable?
As a side question, I’ve been recommended to use SP units as it goes by user defined settings. Is this a best practice?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can either use a dimension resource (e.g.,
android:textSize="@dimen/someSize"), or use a style that does this (per AlexN’s answer), or set the size at runtime viasetTextSize().On newer versions of Android, the user can change the base font size via the Settings application. By using
spfor units, your font sizes will scale along with the base font size. If you use other units (e.g.,dp), your font size will remain the same regardless of what the user has in Settings. It is impossible to say whether any given use ofspis a “best practice” or not — I am sure that there are cases where allowing the font size to change would be a bad thing. By default, though,spis probably the right starting point.