2014-11-15 17 views
0

我得到了這個錯誤在我的xml文件中的佈局文件夾。我把它改到Android:文本=「@字符串/ X」,但隨後表示該上的按鈕:enter image description here硬編碼蜇「x」,應該使用@string資源

這裏是我的main_menu.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="150dp" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="100dp" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Menu" //warning here 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Button 
     android:id="@+id/one_player" 
     android:layout_width="115dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:text="1player" />//warning here 

    <Button 
     android:id="@+id/two_player" 
     android:layout_width="115dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:text="2players" />//warning here 

    <Button 
     android:id="@+id/exit_game" 
     android:layout_width="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_height="115dp" 
     android:text="exitgame" />//warning here 

</LinearLayout> 

回答

2

您需要定義下水庫>值 - > string.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string 
     name="player_1" 
     1player</string> 
</resources> 

串這樣你可以參考你的XML佈局文件的字符串值的任何視圖下: -

<Button 
    android:id="@+id/one_player" 
    android:layout_width="115dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:text="@string/player_1" /> 

有關如何在資源中聲明字符串的更多詳細信息,請參閱link

1

看起來你忘了實際聲明strings.xml中的變量。

+0

我沒有忘記在strings.xml中聲明它們的確,我非常笨拙 – goedkoop

+0

這篇文章應該是一個評論。沒有答案。 –