1

调用 setTextColor 时,TextView 变为黑色或接近黑色。不知道为什么。任何帮助,将不胜感激。

目前使用 holo.light。

  <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"
             android:theme="@android:style/Theme.Holo.Light">

如下设置我的 TextView

  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:text="0"
          android:id="@+id/tvOutput"
          android:textColor="@color/button_text"
          android:textSize="70dp" android:layout_marginRight="16dp"
          android:layout_marginLeft="16dp"
          android:layout_gravity="center"
          android:layout_marginTop="58dp"
          android:gravity="center"/>

当我尝试调用 tvOutput.setTextColor(R.color.laserblue); 时出现问题 R.color.laserblue as: #ff00ddff 但是,它变黑了!我不知道它为什么这样做。对于我尝试的任何颜色。

4

1 回答 1

5

你需要打电话

getResources().getColor(R.color.YOURCOLOR)正确设置颜色。

使用以下代码设置颜色

textView.setTextColor(getResources().getColor(R.color.YOURCOLOR));
于 2013-01-01T06:10:02.697 回答