2011-08-02 36 views
0

我正在創建一個應用程序,點擊一個按鈕後,它將更改爲不同的佈局。一切運作良好,但是當我風格第二佈局的背景TextView的,它崩潰和月食說「找不到源代碼」如果Textview背景被自定義,應用程序崩潰

這裏是TextView中的XML當它不崩潰:

<TextView android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_width="wrap_content" android:layout_below="@+id/textView1" 
    android:layout_centerHorizontal="true" android:layout_marginTop="15dp" 
    android:id="@+id/licenseKey" android:typeface="monospace" 
    android:text="@string/loading" /> 

這當它崩潰的是:

<TextView android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_width="wrap_content" android:layout_below="@+id/textView1" 
    android:layout_centerHorizontal="true" android:layout_marginTop="15dp" 
    android:id="@+id/licenseKey" android:typeface="monospace" 
    android:text="@string/loading" android:background="@string/grey"/> 

下面是活動代碼:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.register); 

    TextView licenseKey = (TextView)findViewById(R.id.licenseKey); 
    licenseKey.setText(generateKey()); 
} 

public String generateKey() { 
    return "D5JO4-7VQP8-D7B3X-L8N0D"; 
} 

對於問題是什麼,我深感難過。 textview通常顯示僞造的許可證代碼,但是一旦我改變它的背景崩潰。我甚至沒有看到第二個佈局。在我的Nexus S Android 2.3.3上進行調試。

回答

0

您應該將android:background屬性設置爲drawable或rgb值,而不是字符串。見here。例如:android:background="#bebebe"

+0

我怎麼會提出,在一個字符串,而不是,所以我可以使用相同的顏色爲其他對象,而不僅僅是一個? – Qasim

0
android:background="@string/grey" 

難道不該

android:background="@android:color/gray" 
相關問題