简体   繁体   English

哪些颜色值可用于GradientDrawable

[英]Which color values can be used for GradientDrawable

In my application i am trying to draw a gradientBackground from code. 在我的应用程序中,我试图从代码中绘制一个gradientBackground。 My goal is to make this background dynamic . 我的目标是让这个背景dynamic

Now is my question this function below is the function i am talking about, and has a parameter int[] colors 现在是我的问题,下面这个函数是我正在讨论的函数,并且有一个参数int[] colors

GradientDrawable(GradientDrawable.Orientation orientation, int[] colors);

Which values can i put in int[] colors? 我可以在int []颜色中添加哪些值? I know the following value works. 我知道以下值有效。

  • 0xAARRGGBB 0xAARRGGBB

But my problem is, i recalculate hash values in my program but they end as a String, but it has to end as an Integer. 但我的问题是,我在我的程序中重新计算哈希值,但它们以字符串结尾,但它必须以整数结束。

And it isn't possible to convert a hash value like: String 0x34F323 to Int 0x34F323. 并且无法将哈希值转换为:String 0x34F323到Int 0x34F323。 When i recalculated the hash value and get: 当我重新计算哈希值并得到:

String: #125BD7

And i use Integer.Decode("#125BD7"); 我使用Integer.Decode(“#125BD7”); The output will be a value of seven numbers. 输出将是七个数字的值。 But this doesn't work in the method of GradientDrawable at the int[] parameter. 但是这在int []参数的GradientDrawable方法中不起作用。 Because all i get is a black background. 因为我得到的只是黑色背景。

Can someone help me with this? 有人可以帮我弄这个吗? Which values can i use in the GradientDrawable method? 我可以在GradientDrawable方法中使用哪些值?

Use Color.parseColor("#45F434"); 使用Color.parseColor("#45F434"); . Which returns integer. 返回整数。 But there should be no G in you color code. 但你的颜色代码中应该没有G Only Hex values are acceptable ( 0-F ). 只有十六进制值是可接受的( 0-F )。

Take a look at the Color class reference. 看一下Color类引用。 Color can be negetive. 颜色可以是negetive。 Take a look at the constants. 看看常数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM