错误说对于硬编码你必须使用@ string / ..只是使用“android:text =”price有什么问题???
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:text="PRICE" />
答案 0 :(得分:1)
字符串资源为应用程序提供可选的文本样式和格式的文本字符串。有三种类型的资源可以为您的应用程序提供字符串:
的字符串 提供单个字符串的XML资源。 字符串数组 提供字符串数组的XML资源。 数量字符串(复数) 带有不同字符串以进行复数化的XML资源。 所有字符串都能够应用一些样式标记和格式化参数。
有关详细信息,请阅读here
此外,最好使用字符串资源,如果必须更改文本,则只更改一个变量
因此,在您的res文件夹中会有另一个名为values的文件夹,然后访问strings.xml文件,在该文件中您将放置一个字符串资源以在您的应用中使用,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">yourAppName</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="price">PRICE</string>
</resources>
然后在你的xml文件中,你将android:text =“PRICE”更改为android:text =“@ string / price”