Q:
Android: How can I change color of TextView within LinearLayout
I have an xml layout with LinearLayout for my custom dialog and the TextViews.
I want to change the color of this TextView (which is in the background_gray layout). When the button is pressed, the background color must go back to normal color. How can I accomplish this?
A:
Please remove android:background="@color/background_gray"
from LinearLayout. And in your main.xml file change:
android:background="@color/background_gray"
to
android:background="@android:color/black"
To change color of TextView, set the style as
And then,
Now use the style as
Button.setBackgroundColor(ContextCompat.getColor(this,R.color.background_gray);
or
Button.setTextColor(ContextCompat.getColor(this,R.color.background_gray);
Hope this helps.
A:
Set the background of your TextView to android:background="@color/background_gray"
and at this point of time,change the color of your textView to your current required color by using textview.setTextColor(getResources().getColor(R.color.your_required_color_here));
and just do set the background of your TextView as android:background="@null" so it will reset the style
A:
i don't know if this can work for u. i have tried. try putting
android:background="@null" in your TextView and then change the color
and
Textview test = (TextView) view.findViewById(R.id.txtMyTextView);
test.setTextColor(Color.parseColor("#000000"));