SetTextcolor using getCurrentTextColor ()

I need to get the current text form of a TextView, and then assign that value to TextView.setTextColor (). But I get a big int -1979711488138 int, how can I get color from it?

+5
source share
4 answers
Integer intColor = -1979711488138; String hexColor = "#" + Integer.toHexString(intColor).substring(2); 

or

 String hexColor = String.format("#%06X", (0xFFFFFF & intColor)); 
+3
source
  public class MainActivity extends Activity { private TextView txtViewIpLable,textView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); textView1.setTextColor(txtViewIpLable.getTextColors()); } private void init() { // TODO Auto-generated method stub txtViewIpLable = (TextView) findViewById(R.id.txtViewIpLable); textView1 = (TextView) findViewById(R.id.textView1); } } 
0
source

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

 textView.setTextColor(textView1.getCurrentTextColor()); 
0
source

You cannot put a number in int, I get -1979711488, which is # 8A000000, i.e. black with 138 alpha. You can get all parts of the color as follows:

 int color = getCurrentTextColor(); int a = Color.alpha(color); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); 

It is really strange why the text color by default is not a solid color, but rather black with an alpha value, since it is more expensive for the system.

0
source

All Articles