2011-12-23 99 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

相关问题