androidtextviewandroid-viewandroid-backgroundandroid-color

Android: Convert Integer for Set Color. Is This Possible to Do It?


I have a question about Set Background Color for a View programmatically.

I have integer value that I would like to use for background color for TextView. Now I have the Integer values of -8076976

Is this possible to use this value to convert for be able to use background color?

Thank you very much

Edit The integer value can be changed because of I used a seek bar that for picking color so that I would like to know convert the integer value and directly set as background color.


Solution

  • In your Color.xml file create a color item with this color followed by a #. Then in your code use:

      getResources.getColor(R.color.color-code);
    

    Update:

    As per your comment you want to show directly the hex value. Look at the code here:

     SetBackgroundColor(Color.parseColor("#000000"));
    

    Replace with your own hex color code.