Using @string resource inside a style definition

社会主义新天地 提交于 2019-12-10 16:16:33

问题


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>

回答1:


You should use the dimens.xml file for dimension values

then reference it @dimen/yourDimensionName

More details here




回答2:


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

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



来源:https://stackoverflow.com/questions/5423365/using-string-resource-inside-a-style-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!