Android dynamic set color for solid color icons

Source: Internet
Author: User

73718363

Used to do a flow of suspended windows, suspended windows with the current network status of the icon and speed of the text, want to change the text color and change the color of the status icon

After the realization of sharing to let everyone refer to the next

First

Here are the key codes
< ImageView   Android:id = "@+id/iv_icon"   android:layout_width= "150DP"  android:layout_height= "150DP"   android:src = "@drawable/icon" />
//set the color of the icon  
 private  void  seticoncolor (ImageView icon, int  R, int  G, int  B, int   a { float  [] ColorMatrix = new  float  []{ 0, 0, 0, 0 0, 0, 0, 0, G,  0, 0, 0, 0, B,  0, 0, 0, (float ) a/255, 0    }; Icon.setcolorfilter ( new   Colormatrixcolorfilter (ColorMatrix));}  
    • Want to know the specific principle can look at this article

Android Learning Note 22: Image Color Processing (ColorMatrix)

If the icon is opaque and does not require a change in transparency, there is a simpler way to implement it.
Icon.setcolorfilter (Color.argb (255, R, G, b));

Android dynamic set color for solid color icons

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.