【发布时间】:2015-08-24 12:23:50
【问题描述】:
这是一个应用程序的一些代码,它只会将 hello world 打印到我的手机上。但是,当我尝试在 Android 工作室中将文本从“@string/hello_world”更改为其他内容(例如“@string/hello”)时,它会引发错误。有人可以帮忙吗?
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
【问题讨论】:
-
你是否在
strings.xml中添加了字符串hello?转到strings.xml中的res -> values ->strings.xml打开它。在那里你找到一行<string name="hello_world">Hello world!</string> -
那是什么(我第一次用这个)
-
如果你的意思是在这个
-
请阅读此文档developer.android.com/samples/BasicNetworking/res/values/… 和developer.android.com/guide/topics/resources/… 并了解
String Resources的用途并尝试一下。它将帮助您走得更远。在TextView上按住CTRL + CLICK"@string/hello_world"将带你到strings.xml那里你可以创建和修改String Resources -
这表示如果你想给
android:text="@string/myapp",那么在strings.xml中应该有<string name="myapp">Hey, This is My App</string>。所以在TextView它显示Hey, This is My App