1

Why only on Android 5.1 or above setTextColor method doesn't works?

TextView TextView32 = (TextView) findViewById(R.id.textView32);
TextView32.setText(String.valueOf(LikesNumber2));
SendLikes2.setBackgroundResource(R.drawable.likeyes);
TextView32.setTextColor(Color.parseColor("#ffffff"));

Strange, but on Android 4.4 and above 30 mobile phones with variable versions textColor changes. Where is a mistake?

XML:

<RelativeLayout                
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_marginBottom="7dp">

     <Button
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/SendLikesHe"
            android:background="@drawable/likezero"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="15dp"
            android:layout_centerHorizontal="true" />

     <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView32"
            android:textColor="#fffb0049"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="14dp"
            android:layout_alignBottom="@+id/SendLikesHe" />

     <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="Like"
            android:id="@+id/textView67_onn"
            android:layout_gravity="center_horizontal"
            android:textSize="13sp"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="false"
            android:layout_below="@+id/SendLikesHe"
            android:textColor="#FB0049" />
</RelativeLayout>
Anjali Tripathi
  • 1,447
  • 9
  • 27
androidFan
  • 33
  • 6

3 Answers3

2

You can use

TextViewObj.setTextColor(getResources().getColor(R.color.Color_Name));

Or use ContextCompat

TextViewObj.setTextColor(ContextCompat.getColor(context,R.color.Color_Name));

getColor(int id) deprecated on Android 6.0 Marshmallow (API 23)

Hope this helps .

Community
  • 1
  • 1
IntelliJ Amiya
  • 70,230
  • 14
  • 154
  • 181
  • 1
    Thanks for your help, but i think problem is in ImageView. It can impose the text (i dont know how i can say it in english - something like "you cann't see text because imageview on them"). So problem isn't solved – androidFan Jan 21 '16 at 20:17
0

You are trying

 TextView32.setTextColor(Color.parseColor("#ffffff"));

which is WHITE color. Is your background color not a white??

Try to set background color gray(#808080) or other and set color as,

TextViewObj.setTextColor(getResources().getColor(R.color.Color_Name));
0
textView.setTextColor(Color.parseColor("#DD1515"));

Above line should work fine. tested in 4.4, 5.1, 6.0

IntelliJ Amiya
  • 70,230
  • 14
  • 154
  • 181
techniqez
  • 125
  • 1
  • 9