android按钮 - 我的第一个应用程序错误

时间:2014-04-25 02:00:31

标签: android

使用我的第一个Android应用程序或更像是学习。 我试图弄清楚我得到的错误:

错误:错误:找不到与给定名称匹配的资源(在'text'处,值为'@ string / save_button')。

我只想将按钮重命名为“Save Me”或“Next”。但似乎无法理解如何绕过它。找不到这方面的简单教程。大部分都涉及几个xml的按钮。请帮忙。它不会让我编译和运行。

谢谢。

<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="com.example.myfirstapp2.MainActivity$PlaceholderFragment" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="top"
    android:inputType="text" />

 <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/save_button" />

</LinearLayout>

编辑:我正在使用Eclipse

5 个答案:

答案 0 :(得分:0)

“重命名按钮”是什么意思? 如您所述,我假设您要将按钮命名为“save me”或“next”。 这样,我想知道你是否有一个字符串值“save_button” 如果没有,请使用

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="save button" />

这应该有用。

答案 1 :(得分:0)

您需要找到res/values/文件夹并在那里打开string.xml。然后在其中添加保存按钮字符串:

样品:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="save_button">Button name Here</string>
    <string name="hello_world">Heelo World</string>

</resources>

答案 2 :(得分:0)

android:text参数引用strings文件中res资源文件夹中的资源。如果您没有在strings.xml中引用名为save_button的字符串,则会导致此错误。

以这种方式命名您的按钮。要命名它,您需要一个参数,例如:

android:id = "@+id/save_button"

所以,这就是你的意思:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/save_button" />

答案 3 :(得分:0)

android:text="@string/hello_world" 

这意味着您需要在res / values strings.xml中添加字符串,如此

<string name="hello_world">hello world.</string>

这样你就可以在R.java中看到hello_world,你可以使用它

答案 4 :(得分:0)

转到res文件并在string.xml文件夹中添加:

<string name="save_button">Save</string>
    <string name="hello_world">Hello World</string>
相关问题