@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground3color(AndroidViewComponent component, Object orientation, int color1, int color2) {
// To set gradient colors as background, what we are actually going to
// do is create a new GradientDrawable object and set it as
// the background of the view. With this approach, it'd be possible to
// create gradients programmatically without editing the manifest
// file which is currently not supported in App Inventor 2.
// Getting the reference to the View of the parameter component using
// the getView() method of AndroidNonVisible class.
View view = component.getView();
// GradientDrawable is a subclass of Drawable class from Android
// support library. It is mostly used to create gradients.
// For more info visit: https://developer.android.com/reference/android/graphics/drawable/GradientDrawable
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation,
new int[] {color1, color2});
// Setting the gradientDrawable as the background of view.
view.setBackground(gradientDrawable);
}
how i converted to 3 colors
in this code at this line
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation,
new int {color1, color2});
i just changed
new int[] {color1, color2});
to
new int {color1, color2, color3});
and
@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground3color(AndroidViewComponent component, Object orientation, int color1, int color2) {
to
@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground3color(AndroidViewComponent component, Object orientation, int color1, int color2,int color3) {
for 3 colors it works perfectly
now my goal is to achieve unlimited colors
so what i did
i first
@SimpleFunction(description = "")
public void SetGradientBackground2color(AndroidViewComponent component, Object orientation,int color1, int color2) {
@SimpleFunction(description = "this block is where u put ur component,colors,u may have dout what is orientation it is where u put the green block i gave in gradients section")
public void SetGradientBackground2color(AndroidViewComponent component, Object orientation, YailList colors) {
// To set gradient colors as background, what we are actually going to
// do is create a new GradientDrawable object and set it as
// the background of the view. With this approach, it'd be possible to
// create gradients programmatically without editing the manifest
// file which is currently not supported in App Inventor 2.
// Getting the reference to the View of the parameter component using
// the getView() method of AndroidNonVisible class.
View view = component.getView();
// GradientDrawable is a subclass of Drawable class from Android
// support library. It is mostly used to create gradients.
// For more info visit: https://developer.android.com/reference/android/graphics/drawable/GradientDrawable
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation,
new int {colors} );
// Setting the gradientDrawable as the background of view.
view.setBackground(gradientDrawable);
}
and error
is
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Gradient\Gradient.java:52: error: incompatible types: YailList cannot be converted to int
[javac] new int {colors} );
[javac] ^
my code
int[] array = new int[list.size()]; int index = 0;for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }
GradientDrawable gradientDrawable = new GradientDrawable(
(GradientDrawable.Orientation) orientation, array);
my error
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Gradient\Gradient.java:50: error: cannot find symbol
[javac] int[] array = new int[list.size()]; int index = 0; for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }
[javac] ^
[javac] symbol: variable list
[javac] location: class Gradient
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Gradient\Gradient.java:50: error: cannot find symbol
[javac] int[] array = new int[list.size()]; int index = 0; for(String e : list.toStringArray()) { array[index] = Integer.parseInt(e); index++; }
[javac] ^
[javac] symbol: variable list
[javac] location: class Gradient