【发布时间】:2018-07-23 07:32:01
【问题描述】:
我是 Android 开发的新手。我最近下载了最新的 Android Studio 3.0.1。我正在使用华莱士杰克逊“绝对初学者的 Android 应用程序”。根据本书创建(第一个)应用程序时,我有 2 个 XML 文件:
- activity_main.xml
- strings.xml
activity_main.xml 文件硬编码了android:txt="Hello World!"
本书指导您修改文件 1 以引用 strings.xml 获取此字符串。
文件 2,strings.xml,被修改为添加第二行,其中包含通过删除“!”稍微修改的字符串。
当我查看 Android SDK 中的预览布局窗格时,我没有看到字符串“Hello World”
相反,我看到了“@string”。
我确定我做的事情基本上是错误的,或者错过了一个或多个关键步骤。
这是 activity_main.xml 文件(文件 1)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.michael.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
这是 strings.xml 文件(文件 2):
<resources>
<string name="app_name">My Application</string>
<string name="app_message">Hello WORLD</string>
</resources>
【问题讨论】: