您的位置:首页 > 其它

How to solve Error: This attribute must be localized. 两种方式

2012-07-31 22:16 477 查看
引用:http://stackoverflow.com/questions/8446337/how-to-solve-error-this-attribute-must-be-localized-at-text-with-value-top

down vote
Best practice for Android apps is to define all of the non-dynamic content in resource files. This lets you define different resource files for different languages, for example. Normally, this is just a recommendation and the Android SDK doesn't complain if you hard-code values in your layout xml. The Android source build system, however, requires that all strings be defined in a "values" resource. This is probably intended to protect system builders from accidentally leaving content in a system image that won't display in the user's chosen language.

What you need to do is move those string values out of the layout and define them in
res/values/
instead. The usual place for string values is in
res/values/strings.xml
, but the actual file can be named anything you like as long as it's in that directory.

For example, in res/values/string.xml:

<stringname="topLeftContent">TOP_LEFT</string>

And in your
main.xml
layout, refer to the content by name:

android:text="@string/topLeftContent"

For more details on the how and why of this, see Google's documentation on Localization in Android.

share|improve this answer
answered Jan 12 at 19:05



Greg Hensley
111

Was this post useful to you?

up vote0down vote

You can use

LOCAL_MODULE_TAGS := tests

in the Android.mk to omits the localization check.

Another way is to disable localization check in build system. Comment the line 81 in
build/core/package.mk


#LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: