Working with 6-digit(RGB) and 8-digit hex colors (ARGB) in android

Samsul Hoque
25

RGB and ARGB: 
   
        RGB is a 3-channel format containing data for Red, Green, and Blue. ARGB is a 4-channel format containing data for Alpha, Red, Green and Blue .
There is no use to the Alpha channel other than making the color transparent/opaque (or partially transparent; translucent).
You might find an RGB value packed into 16 bits, with 5 bits for Blue and Red, and 6 bits for Green (green gets more bits because the eye is more discerning to shades of green). You might also find an RGBA value packed into 16 bits, with 5 bits for each color and 1 bit for alpha. With one bit, you can only make the color fully transparent or not transparent at all.
Typically nowadays, you'll find RGB and RGBA packed into 32 bit values, with 8 bits for each color, and 8 bits for alpha (or left blank for RGB).


Use in Android:
A color value defined in XML. The color is specified with an RGB value and alpha channel. You can use a color resource any place that accepts a hexadecimal color value. You can also use a color resource when a drawable resource is expected in XML (for example, android:drawable="@color/green").
The value always begins with a pound (#) character and then followed by the Alpha-Red-Green-Blue information in one of the following formats:
  • #RGB
  • #ARGB
  • #RRGGBB
  • #AARRGGBB
Note: A color is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine color resources with other simple resources in the one XML file, under one <resources> element.
FILE LOCATION:
res/values/colors.xml
The filename is arbitrary. The <color> element's name will be used as the resource ID.
RESOURCE REFERENCE:
In Java: R.color.color_name
In XML: @[package:]color/color_name
SYNTAX:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color
        name="color_name"
        >hex_color</color>
</resources>
ELEMENTS:
<resources>
Required. This must be the root node.
No attributes.
<color>
A color expressed in hexadecimal, as described above.
attributes:
name
String. A name for the color. This will be used as the resource ID.
EXAMPLE:
XML file saved at res/values/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="opaque_red">#f00</color>
   <color name="translucent_red">#80ff0000</color>
</resources>
This application code retrieves the color resource:
Resources res = getResources();
int color = res.getColor(R.color.opaque_red);
This layout XML applies the color to an attribute:
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/translucent_red"
    android:text="Hello"/>
Reference : http://developer.android.com/guide/topics/resources/more-resources.html#Color

Post a Comment

25Comments
  1. this is really too useful and have more ideas from yours. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.
    school websites uk

    ReplyDelete
  2. thanks for shared wonderful information of giving best information.its more useful and more helpful. great doing keep sharing
    GMAT coaching chennai

    ReplyDelete
  3. Nice article. It's very helpful to me. Thank you for share with us. Can you please check my hexadecimal color codes online tool.

    ReplyDelete
  4. This blog is simple and easy to understand for the android app developers to actually know the real purpose of RGB and ARGB color coding done in XML formats. These example programs should help the Android App Development Company to build a highly interactive and responsive android application and achieve a better deal of user engagements. Thanks for the Blog Post.

    ReplyDelete
  5. Very nice article excellent information thanks for share.Keep updating thanks
    GRE classes chennai

    ReplyDelete
  6. I admire what you have done here. I love the part where you say you are doing this to give back but I would assume by all the comments that is working for you as well. Do you have any more info on this? online business

    ReplyDelete
  7. Great Article android based projects

    Java Training in Chennai Project Center in Chennai Java Training in Chennai projects for cse The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai

    ReplyDelete
  8. This is really useful and I have more ideas from you. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.
    top mobile app development company
    Development Cost of an Ecommerce Mobile App

    ReplyDelete
  9. Bravo! I admire how you've quoted every sentence with valuable examples and statistics. I must mention your blog has a good readability and less jargon. Appsquadz.com is one such website that posts blogs in the same niche with loaded information.

    ReplyDelete
  10. Great share and want to here about SEO Company in pune and want best seo pune team, then visit us
    SEO Company in Pune
    SEO Services Pune

    ReplyDelete
  11. Great article. Keep writing such kind of information on your blog.
    Wall Mirror
    Whiskey Glass

    Venetian Mirror

    ReplyDelete
  12. Good Blog, Such a Nice Content, Informative for Readers Keep Posting. Call center software | Best call center software

    ReplyDelete
  13. I appreciate your website. Its really very help full. Thanks for sharing the great information

    Unified Communications

    ReplyDelete
  14. I like the valuable information you provided in your article. I am sure I will learn many new things here! Good luck.

    Also visit us for
    Urine Samples
    Plasma Samples
    Cancer Samples

    ReplyDelete
  15. I just loved your blog! I also want to suggest students that who are reading my comment about my website thestudenthelpline.com. such as take online Assignment Help Australia and many more paid like homework help.

    ReplyDelete
Post a Comment