Posts

Showing posts with the label GradientDrawable in Android

Using GradientDrawable as background in Sketchware Android Project

Image
The public class GradientDrawable can be used to create a Drawable image with gradient of several colors which can be set as the background of any View. The codes provided below shows how to use GradientDrawable in Sketchware Android Project. The codes provided below should be added in onCreate event, in add source directly block. 1. To set a single color as background of any View, use following code: android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable(); gd.setColor(Color.parseColor("#ff000000")); linear1.setBackground(gd); Or android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable(); gd.setColor(Color.WHITE); linear1.setBackground(gd); Here gd is a GradientDrawable. Here hex color code can be use to set background color. And here gd is set as background of linear1. It can also be set as background of any other View (like button1, etc.). 2. To create a GradientDrawabl...