0

I've got this super simple question I can't find an answer to. I want to make a variable which I could then use for multiple elements. Something like this in strings.xml:

<resources>
    <string name="textSize">20sp</string>
</resources>
...
<EditText android:textSize="@string/textSize" />

But this does not work. I was able to accomplish what I wanted the following way in themes.xml:

<style name="textSize">
    <item name="android:textSize">20sp</item>
</style>
...
<EditText android:theme="@style/textSize" />

But it seems too complicated for just a single value, is there a better way?

Kerap
  • 30
  • 1
  • 4
  • If you're wanting a dimension resource, you need to specify a `dimen`, not `string`. So `20sp` – Henry Twist Jul 15 '21 at 18:14
  • Please try this, " " – Sabodh Jul 15 '21 at 18:18
  • @HenryTwist That works, thank you. – Kerap Jul 15 '21 at 18:21

1 Answers1

0

As suggested in the comments, this looks like a dimen property rather than a string.

Just like strings.xml, you can have another file (usually dimen.xml) with dimensions. Your case could look like this:

<resources>
    <dimen name="bigText">20sp</string>
</resources>

It also allows you to have different settings for different configurations (for example, screen sizes here: How to define dimens.xml for every different screen size in android?).

You can find the documentation here: https://developer.android.com/guide/topics/resources/more-resources?hl=en#Dimension

JonZarate
  • 841
  • 6
  • 28