无法从显示中删除%s

时间:2017-11-21 18:05:05

标签: java android xml

Why is %s getting printed?

我想删除屏幕上显示的%s,但不知道我做错了什么。有什么帮助吗?

Strings.xml文件 -

<!-- Name of the customer [CHAR LIMIT=NONE] -->
    <string name="user_name">
        Name: <xliff:g id="name" example="Amy">%s</xliff:g>
    </string>

主XML文件 -

 <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint = "@string/user_name"
        android:id = "@+id/name_input"/>

Java文件 -

String priceMessage = getString(R.string.user_name, customer);

1 个答案:

答案 0 :(得分:0)

更改

  <!-- Name of the customer [CHAR LIMIT=NONE] -->
<string name="user_name">
    Name: <xliff:g id="name" example="Amy">%s</xliff:g>
</string>

要:

 <!-- Name of the customer [CHAR LIMIT=NONE] -->
<string name="user_name">Name:</string>

然后,当您在Java中引用此字符串时,只要您为该特定语言添加了特定的strings.xml文件,该值就会更改为您选择的特定语言。