Android 模拟器中的硬编码警告
我收到这样的警告: 硬编码字符串“按钮名称”应使用@string资源 这是什么意思? 如果我保持原样,应用程序中是否存在任何问题(特别是与gps相关的问题) 这是按钮:Android 模拟器中的硬编码警告,android,android-emulator,Android,Android Emulator,我收到这样的警告: 硬编码字符串“按钮名称”应使用@string资源 这是什么意思? 如果我保持原样,应用程序中是否存在任何问题(特别是与gps相关的问题) 这是按钮: android:id="@+id/retrieve_location_button" android:text="Retrieve Location" android:layout_width="wrap_content" android:layout_height="wrap_content" 这意味着按钮的布局XML应该如
android:id="@+id/retrieve_location_button"
android:text="Retrieve Location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
这意味着按钮的布局XML应该如下所示:
<button android:id="@+id/retrieve_location_button" android:text="@string/location_text" android:layout_width="wrap_content" android:layout_height="wrap_content">
其中您的strings.xml将具有:
<resources>
<string name="location_text">Retrieve Location</string>
</resources>
检索位置
这是一个国际化和翻译问题,而不是影响程序运行时的问题。您应该将用户可见字符串外部化,以便可以翻译应用程序。这只是一个警告。。也可以忽略。。但它的意思是。。安装使用硬编码值,如android:text=“检索位置”。。您可以将此值存储在res/values文件夹中,然后使用。。