androidandroid-color

changing the Background color also affect text color


I have a table made of buttons and when the Background color of the button is changing so does the text color.

Note - The text on every view is the black dot as you can in the images below.


For example, when I am changing the color for some of the views to blue it looks like this (the text is white):

enter image description here

The problem start when the background color is white, causing the text to disappear (the text is no longer visible inside the blue area) :

enter image description here


The Question

How can I prevent the text from changing its color when the view background color is changing?

My code

Whenever a button is clicked this line is getting called to change its background color:

 cell.setBackgroundColor(currentColor) //cell = the view , currentColor = the background color

Solution

  • I don't know why the text color kept changing but I just changed the text color of that view as well when he got clicked and that solved the problem:

     cell.setOnClickListener { //cell = the view
            cell.setTextColor(Color.BLACK)      
            cell.setBackgroundColor(currentColor)
        }