Computer/Android
[Android] Color
jamezc
2017. 2. 19. 01:07
Color 지정방법에 대한 다양한 방법 소개
You can use various functions from the Color
class to get the same effect of course.
holder.text.setTextColor(Color.RED);
Color.parseColor
(Manual) (like LEX uses)text.setTextColor(Color.parseColor("#FFFFFF"));
Color.rgb
andColor.argb
(Manual rgb) (Manual argb) (like Ganapathy uses)holder.text.setTextColor(Color.rgb(200,0,0)); holder.text.setTextColor(Color.argb(0,200,0,0));
And of course, if you want to define your color in an
XML
file, you can do this:<color name="errorColor">#f00</color>
because the
getColor()
function is deprecated1, you need to use it like so:ContextCompat.getColor(context, R.color.your_color);
You can also insert plain HEX, like so:
myTextView.setTextColor(0xAARRGGBB);
Where you have an alpha-channel first, then the color value.
Check out the complete manual of course, public class Color extends Object.
https://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)