Salsero69
Salsero69

Reputation: 2240

Using @string resource inside a style definition

I have something like the following (shown below) defined in my styles.xml file. But Android crashes due to the use of the @string/fontExtraLarge. I'm assuming it's because of the order of definition, but is this legal.

I could use the style 'parent' attribute to resolve this, but for only one style definition doesn't make sense. Is there a way to resolve this problem.

BTW, the error I get is Unable to Inflate XML which points to the layout.XML, but really this file is causing this issue.

<!-- **** FONT SIZES **** -->
<string name="fontExtraLarge">20sp</string>
<string name="fontLarge">18sp</string>
<string name="fontMedium">16sp</string>
<string name="fontSmall">10sp</string>
<string name="fontNormal">10sp</string>'

<style name="screenHeader">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textStyle">bold</item>
    <item name="android:typeface">serif</item>
    <item name="android:textSize">@string/fontExtraLarge</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:gravity">center</item>
</style>

Upvotes: 4

Views: 3406

Answers (2)

Kurru
Kurru

Reputation: 14331

You should use the dimens.xml file for dimension values

then reference it @dimen/yourDimensionName

More details here

Upvotes: 3

Abhinav
Abhinav

Reputation: 39952

All strings go inside res/values/strings.xml.

Also all style tags have to be enclosed with the <resources/> tag.

Upvotes: 0

Related Questions