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

简介: 引用:http://stackoverflow.com/questions/8446337/how-to-solve-error-this-attribute-must-be-localized-at-text-with-value-top down vote Best ...

引用:http://stackoverflow.com/questions/8446337/how-to-solve-error-this-attribute-must-be-localized-at-text-with-value-top

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
 
Was this post useful to you?     
 

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 inbuild/core/package.mk

#LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
相关文章
|
7月前
|
算法 C# C++
HALCON error #1201: Wrong type of control parameter: 1 in operator threshold
HALCON error #1201: Wrong type of control parameter: 1 in operator threshold
VS2005 error C2864 only static const integral data members can be initialized within a class
VS2005 error C2864 only static const integral data members can be initialized within a class
error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
98 0
error: ‘nullptr’ was not declared in this scope
error: ‘nullptr’ was not declared in this scope
190 0
|
计算机视觉
opencv出错:error: (-213:The function/feature is not implemented) Unknown/unsupported array type
opencv出错:error: (-213:The function/feature is not implemented) Unknown/unsupported array type
406 0
error: static assertion failed: Signal and slot arguments are not compatible.
error: static assertion failed: Signal and slot arguments are not compatible.
error: static assertion failed: Signal and slot arguments are not compatible.
|
Java C++
程序运行问题排查和解决:an instance of ‘std::logic_error‘what(): basic_string::_M_construct null not valid
程序运行问题排查和解决:an instance of ‘std::logic_error‘what(): basic_string::_M_construct null not valid
1069 0
使用代码判断某个note是否已经implemented
使用代码判断某个note是否已经implemented
99 0
使用代码判断某个note是否已经implemented