0

これは、Android チュートリアルの 1 つから貼り付けたコードです。しかし、これら3つのエラーが発生しますか? 助けてください

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is my first Android Application!" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="And this is a clickable button!" />

</LinearLayout>

Error: No resource found that matches the given name (at 'text' with value '@string/hello'). main.xml /Helloworld/res/layout line 6 Android AAPT Problem

[I18N] Hardcoded string "And this is a clickable button!", should use @string resource main.xml /Helloworld/res/layout line 17 Android Lint Problem

[I18N] Hardcoded string "This is my first Android Application!", should use @string resource main.xml /Helloworld/res/layout line 13 Android Lint Problem

4

4 に答える 4

3

追加する必要があります

<resources>
     <string name="hello">Hello World</string>
     <string name="app_name">My app</string>
</resources>

最善の策は、プログラムで文字列を追加することです。

TextView tv = (TextView)findViewById(R.id.text1);     //text1 is the id u provide in xml file
tv.setText("Hello World");

詳細は次のとおりです: android:text="@string/hello" と通常の右クリックの違い -> テキスト ビュー コンポーネント -> EditText

于 2012-09-28T14:32:03.257 に答える
1

これを試して、

String.xml ファイル

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
    <string name="hello">Hello World</string>
    <string name="first_application">This is my first Android Application!</string>
    <string name="clickable_button">And this is a clickable button!</string>
</resources>

あなたのxml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical">
      <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello"/>
      <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/first_application"/>
      <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/clickable_button"/>
</LinearLayout>
于 2012-09-28T14:35:11.833 に答える
1

最初の1つ。res/values の strings.xml で文字列「Hello」を定義していません

<string name="hello">Hello!</string>

2 と 3 は警告のみです。文字列はローカライズできないため、layout.xml に文字列をハードコーディングしないでください。「こんにちは」と同じテクニックを使用する必要があります。

于 2012-09-28T14:30:59.893 に答える
0

@stringres/valuesというフォルダー内の xml ファイルを参照するとstrings.xml、次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Enter your "hello" text you want displayed here</string>
</resources>

他のエラーは、上記のように、それらの文字列も作成することを提案しています。

于 2012-09-28T14:33:18.883 に答える