4

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>

2 Answers 2

3

You should use the dimens.xml file for dimension values

then reference it @dimen/yourDimensionName

More details here

1
0

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

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

2
  • 1) I tried with the strings defined in the styles.xml and the values.xml file with no change. 2) There is a resource tag around my definitions. My application does work without the string definitions. So it is not a syntax issue. It is strictly an issue with using @string within a style definition.
    – Salsero69
    Mar 24, 2011 at 18:09
  • My bad. Didn't see that you were setting the string values as dimensions.
    – Abhinav
    Mar 24, 2011 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.