user3616181
user3616181

Reputation: 1055

Can't set textSize TextView by strings.xml in my Android project

When I set android:textSize as a hard string e.g. 50dp my program works great, but if I save this size in strings.xml and use it like android:textSize="@string/my_size" I get many of errors.

Could anybody tell me what am I doing wrong?

Upvotes: 2

Views: 1222

Answers (3)

SMR
SMR

Reputation: 6736

instead of using strings.xml to store values you should rather use res/values/dimens.xml to store values for the text size like this:

<dimen name="txtsize">50sp</dimen>

NOTE: instead of using dp you should use sp for text size.

Upvotes: 1

In dimens.xml write

 <dimen name="my_size">16sp</dimen>

and use:

android:textSize="@dimen/my_size"

Upvotes: 2

TofferJ
TofferJ

Reputation: 4784

You should put the value in dimens.xml NOT in strings.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="font_size">50dp</dimen>
</resources>

Upvotes: 0

Related Questions