1

I want to create a custom theme for my application, but I have a small problem. In my TextViews I use different textColors so for my custom theme i put

<item name="android:textColor">@color/myColor</item>

The problem is: How can I set different textColors for different TextViews? Thanks in advance.

Popnoodles
  • 28,090
  • 2
  • 45
  • 53
user3717163
  • 61
  • 2
  • 8

2 Answers2

1

Don't define it in theme then, create a style and apply it to different textviews.

Mehul Shah
  • 391
  • 3
  • 7
1

You could use TextView#setTextColor:

text.setTextColor(Color.rgb(250,20,250));

Here are some examples where you can also get the text color from resources:

text.setTextColor(getResources().getColor(R.color.myColor));

If you absolutely want to use Theme/Styles you can set a custom style for each TextView:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Sample Text"
        style="@style/my_style" />

Here is a good explanation about creating styles!

Community
  • 1
  • 1
Andres
  • 6,080
  • 13
  • 60
  • 110