I want to be able to store a font size (18sp) in a resource so that a lot of my layouts will use so that I can easily change the size in the future if I need to. I\'ve a st
Create a dimens.xml file in your res directory with contents similar to this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="some_text_size">18dp</dimen>
</resources>
Then instead of referencing it like @string/blah, use @dimen/blah.
Use this as your XML resource and call it from where ever you want...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
</resources>
Then call this in code:
Resources res = getResources();
float fontSize = res.getDimension(R.dimen.font_size);