我正在学习本地化和显示文本,具体取决于设备上的默认语言环境设置。
一行代码出现问题我无法弄清楚原因,因为示例项目具有完全相同的代码而没有任何错误。
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream">Add Whipped Cream?
<xliff:g id="hasWhippedCream" example="true">%b</xliff:g></string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate">Add Chocolate?
<xliff:g id="hasChocolate" example="true">%b</xliff:g></string>
/**
* This method creates the string to display
*/
private String createOrderSummary
(String enteredName, int price, boolean hasWhippedCream, boolean hasChocolate)
{
String orderSummary = getString(R.string.order_summary_name, enteredName)
+ "\n" + getString(R.string.order_summary_whipped_cream, hasWhippedCream)
+ "\n" + getString(R.string.order_summary_chocolate, hasChocolate)
+ "\n" + getString(R.string.order_summary_quantity, quantity)
+ "\n" + getString(R.string.order_summary_price, price)
+ "\n" + getString(R.string.thank_you);
return orderSummary;
}
getString(R.string.order_summary_chocolate, hasChocolate)
带有红色下划线并显示this
我真的不明白,为什么第一个字符串order_summary_whipped_cream
完全正常,order_summary_chocolate
给我这些错误 - 它们是相同的,只有名称不同