Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTextcolor by using getCurrentTextColor()

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?

like image 236
Arcadii Rubailo Avatar asked Aug 13 '15 10:08

Arcadii Rubailo


People also ask

How do I change text color in XML?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .

How do I change the color of my text on Kotlin?

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.


2 Answers

Integer intColor = -1979711488138;
String hexColor = "#" + Integer.toHexString(intColor).substring(2);

or

String hexColor = String.format("#%06X", (0xFFFFFF & intColor));
like image 152
sasikumar Avatar answered Oct 30 '22 09:10

sasikumar


Suppose you want to set color from textView1 to textView then you can do like this:

textView.setTextColor(textView1.getCurrentTextColor());
like image 29
Anand Singh Avatar answered Oct 30 '22 10:10

Anand Singh