Create a new color drawable

后端 未结 6 769
时光说笑
时光说笑 2021-01-30 12:43

I am trying to convert a hex value to an int so I can create a new color drawable. I\'m not sure if this is possible, but according to the documentation, it should. It plainly a

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 13:02

    Since you're talking about hex you have to start with 0x and don't forget the opacity.

    So basically: 0xFFFF6666

    ColorDrawable cd = new ColorDrawable(0xFFFF6666);
    

    You can also create a new colors.xml file into /res and define the colors like:

    
    
        #FF6666
    
    

    and simply get the color defined in R.color.mycolor

    getResources().getColor(R.color.mycolor)
    

提交回复
热议问题