@@ -193,6 +193,14 @@ private LinearGradient getLinearGradient() {
193
193
GradientColor gradientColor = colorAnimation .getValue ();
194
194
int [] colors = applyDynamicColorsIfNeeded (gradientColor .getColors ());
195
195
float [] positions = gradientColor .getPositions ();
196
+
197
+ // Add check for minimum colors
198
+ if (colors .length < 2 ) {
199
+ // If only one color, duplicate it to create a solid color gradient
200
+ colors = new int []{colors [0 ], colors [0 ]};
201
+ positions = new float []{0f , 1f };
202
+ }
203
+
196
204
gradient = new LinearGradient (startPoint .x , startPoint .y , endPoint .x , endPoint .y , colors ,
197
205
positions , Shader .TileMode .CLAMP );
198
206
linearGradientCache .put (gradientHash , gradient );
@@ -210,13 +218,21 @@ private RadialGradient getRadialGradient() {
210
218
GradientColor gradientColor = colorAnimation .getValue ();
211
219
int [] colors = applyDynamicColorsIfNeeded (gradientColor .getColors ());
212
220
float [] positions = gradientColor .getPositions ();
221
+
222
+ // Add check for minimum colors
223
+ if (colors .length < 2 ) {
224
+ // If only one color, duplicate it to create a solid color gradient
225
+ colors = new int []{colors [0 ], colors [0 ]};
226
+ positions = new float []{0f , 1f };
227
+ }
228
+
213
229
float x0 = startPoint .x ;
214
230
float y0 = startPoint .y ;
215
231
float x1 = endPoint .x ;
216
232
float y1 = endPoint .y ;
217
233
float r = (float ) Math .hypot (x1 - x0 , y1 - y0 );
218
234
if (r <= 0 ) {
219
- r = 0.001f ;
235
+ r = 0.001f ;
220
236
}
221
237
gradient = new RadialGradient (x0 , y0 , r , colors , positions , Shader .TileMode .CLAMP );
222
238
radialGradientCache .put (gradientHash , gradient );
0 commit comments