1

エラーは、ハードコードされた場合は @string/.. を使用する必要があることを示しています。

<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" />

4

1 に答える 1

1

文字列リソースは、オプションのテキスト スタイルと書式設定を使用して、アプリケーションにテキスト文字列を提供します。アプリケーションに文字列を提供できるリソースには、次の 3 種類があります。

単一の文字列を提供する文字列 XML リソース。String Array 文字列の配列を提供する XML リソース。Quantity Strings (Plurals) 複数形化のために異なる文字列を運ぶ XML リソース。すべての文字列は、いくつかのスタイリング マークアップとフォーマット引数を適用できます。

詳細については、こちらをお読みください

また、文字列リソースを使用することをお勧めします。テキストを変更する必要がある場合は、変数を 1 つだけ変更します。

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" に変更します。

于 2015-07-01T20:18:43.663 に答える