使用@string资源的样式定义中 [英] Using @string resource inside a style definition

查看:161
本文介绍了使用@string资源的样式定义中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面我styles.xml文件中定义(如下图所示)。但是Android崩溃,由于使用了@字符串/ fontExtraLarge的。我猜想这是因为定义的顺序,但是这是合法的。

我可以用风格'父'属性来解决这个问题,但只有一个样式定义是没有意义的。有解决此问题的一种方式。

顺便说一句,我得到的错误是无法充气XML,它指向layout.XML,但实际上这个文件引起此问题。

 <! -  ****字体大小****  - >
<字符串名称=fontExtraLarge>&20SP LT; /串>
<字符串名称=fontLarge> 18sp< /串>
<字符串名称=fontMedium>&16SP LT; /串>
<字符串名称=fontSmall>&10SP LT; /串>
<字符串名称=fontNormal>&10SP LT; /串>'<样式名称=screenHeader>
    <项目名称=机器人:layout_width>&FILL_PARENT LT; /项目>
    <项目名称=机器人:layout_height>&WRAP_CONTENT LT; /项目>
    <项目名称=机器人:文字样式>大胆< /项目>
    <项目名称=机器人:字体>&衬线LT; /项目>
    <项目名称=机器人:TEXTSIZE> @字符串/ fontExtraLarge< /项目>
    <项目名称=机器人:文字颜色> @色/白< /项目>
    <项目名称=安卓重力>中心< /项目>
< /风格>


解决方案

您应该使用维值dimens.xml文件

然后引用它@扪/ yourDimensionName

这里更多细节

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>

解决方案

You should use the dimens.xml file for dimension values

then reference it @dimen/yourDimensionName

More details here

这篇关于使用@string资源的样式定义中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆