2011-12-23 93 views
1

我在android中使用TextView和EditText和Button開發了一個基本的UI活動頁面。我已經將TextView textColor設置爲某個十六進制值,並且因此我的應用程序崩潰了,如果刪除了textColor,則表示應用程序完美運行。 目標SDK 2.3 =這裏 是代碼由於main.xml中的T​​extColor導致Android應用程序崩潰

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:padding="15dp" 
    android:gravity="center_vertical|center_horizontal"> 
    <TextView android:id="@+id/textView" android:text="Enter search Key" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:textStyle="bold" android:textColor="#ff3300" 
     android:layout_gravity="left" /> 
    <EditText android:id="@+id/searchkey" android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:hint="Search Key ..." /> 
    <Button android:text="@string/button" android:layout_height="wrap_content" 
     android:id="@+id/button1" android:layout_width="wrap_content" /> 
</LinearLayout> 

我們可以設置文字顏色爲TextView的或者是有別的東西是錯誤的代碼。

在此先感謝...

+0

crash log please .. – 2011-12-23 09:55:36

+0

其對我來說工作很好.. – 2011-12-23 09:56:21

+0

感謝他們工作 – 2011-12-23 10:09:45

回答

3

您需要資源定義在資源文件中顏色/值文件夾

<resources> 
<color name="mycolor">#33b5e5</color> 
</resources> 

而且在版式文件

使用 @色/ mycolor指定
<TextView android:id="@+id/textView" android:text="Enter search Key" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:textStyle="bold" android:textColor="@color/mycolor" 
    android:layout_gravity="left" /> 
+0

它的工作謝謝:)與一個我的問題是我已經提到了小寫字母的顏色值例如。 ff3300而不是FF3300任何方式感謝您的幫助:) – 2011-12-23 10:08:18

相關問題