I need to get current text color form TextView and then assign this value to TextView.setTextColor(). But I get a large int -1979711488138, how can I get a color from it?
In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .
Change Text Color of TextView in Kotlin File We can get the reference to TextView widget present in layout file and change the color dynamically with Kotlin code. To set the color to the TextView widget, call setTextColor() method on the TextView widget reference with specific color passed as argument.
Integer intColor = -1979711488138;
String hexColor = "#" + Integer.toHexString(intColor).substring(2);
or
String hexColor = String.format("#%06X", (0xFFFFFF & intColor));
Suppose you want to set color from textView1
to textView
then you can do like this:
textView.setTextColor(textView1.getCurrentTextColor());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With