无法在android中显示来自资源的字符串

时间:2013-10-28 05:54:17

标签: android textview

我正在尝试显示资源

中的字符串

我在values文件夹

中显示了字符串的资源

activity_main.xml中

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        android:paddingTop="10dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="140dp"
            android:background="@drawable/frame_background_for_rounded_corners_white_bkg" >

            <ImageView
                android:id="@+id/image1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/image_view_background_white_background" />

            <Button
                android:id="@+id/button1"
                android:layout_width="116dp"
                android:layout_height="wrap_content"
                android:background="@drawable/button_round_cornered_white_background"
                android:text="Button" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="141dp"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/button1"
                android:gravity="center"
                android:text="@string/BuffetOfferings-Breakfast-statement"
                android:textColor="#000000"
                android:textSize="24sp" />

        </RelativeLayout>
    </RelativeLayout>

在值文件夹


styles.xml

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

<resources>

    <style name="AppTheme" parent="android:Theme.Light" />

    <color name="TextColorForTextAboveImage">#FFFFFF</color>


    <string name="BuffetOfferings-Breakfast-statement">Tap the "Breakfast" to offer, then the days and time of its offerings to your customers</string>


</resources>

我的输出 ::

enter image description here

显然,您可以看到而不是要显示的文字....参考本身正在显示

如何解决此问题!

4 个答案:

答案 0 :(得分:1)

您的字符串名称需要使用_而不是-

<string name="BuffetOfferings_Breakfast_statement"></string>

答案 1 :(得分:0)

您需要从name属性中删除您的短划线( - )。

 <string name="BuffetOfferingsBreakfaststatement">Tap the "Breakfast" to offer, then the days and time of its offerings to your customers</string>

有关详细信息,请参阅Document

答案 2 :(得分:0)

将资源属性替换为

 <string name="BuffetOfferings_Breakfast_statement">Tap the "Breakfast" to offer, then the days and time of its offerings to your customers</string>

替换连字符&#39; - &#39;用下划线&#39; _&#39;

答案 3 :(得分:0)

您无法直接在styles.xml中定义字符串,而不能引用strings.xml的字符串。

您应该在 strings.xml 中定义字符串并删除' - '使用'_'

strings.xml

像这样使用

<string name="BuffetOfferings_Breakfast_statement">Tap the "Breakfast" to offer, then the days and time of its offerings to your customers</string>

希望这对你有所帮助。