开发者

Application crashes if Textview background is customized

开发者 https://www.devze.com 2023-03-24 14:08 出处:网络
I am making an application, after clicking a button it changes to a different开发者_Python百科 layout. All works well, but when I style the textView in the 2nd layout\'s background, it crashes and on

I am making an application, after clicking a button it changes to a different开发者_Python百科 layout. All works well, but when I style the textView in the 2nd layout's background, it crashes and on eclipse says "Source not found"

Here is the XML of the textview when it doesnt crash:

<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" />

Here it is when it crashes:

<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"/>

Here is the activity code:

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";
}

I am seriously stumped as to what the problem is. The textview normally shows the fake license code but once i change the background it crashes. I dont get to even see the 2nd layout. Debugging on my Nexus S Android 2.3.3.


You should set the android:background attribute to a drawable or a rgb value, not a string. See here.

For example: android:background="#bebebe".


android:background="@string/grey"

Shouldn't that be

android:background="@android:color/gray"
0

精彩评论

暂无评论...
验证码 换一张
取 消