效果
aaa.png
源码
"ui";
importClass(android.graphics.Color);
importClass(android.graphics.drawable.GradientDrawable);
importClass(android.text.Spannable);
importClass(android.text.SpannableStringBuilder);
importClass(android.text.style.ForegroundColorSpan);
importClass(android.graphics.LinearGradient);
importClass(android.graphics.Shader);
importClass(android.graphics.Bitmap);
importClass("android.graphics.BitmapFactory");
importClass(android.graphics.BitmapShader);
ui.layout(
<vertical margin="16 16 16 16">
<input id="input1" padding="20"></input>
<View h="60dp"></View>
<input id="input2" padding="20"></input>
</vertical>
);
let view;
view = ui.input1;
setBackgroundRoundGradientDottedRectangle(view);
view = ui.input2;
setBackgroundRoundGradientCornerRadii(view);
// ====================自定义函数===============================================================================================
function setBackgroundRoundGradientDottedRectangle(view) {
gradientDrawable = new GradientDrawable();
gradientDrawable.setShape(GradientDrawable.LINEAR_GRADIENT);
gradientDrawable.setStroke(10, Color.GREEN, 30, 30);
view.setBackground(gradientDrawable);
}
function setBackgroundRoundGradientCornerRadii(view) {
gradientDrawable = new GradientDrawable();
gradientDrawable.setShape(GradientDrawable.RECTANGLE);
gradientDrawable.setColor(colors.parseColor("#7c5352"));
gradientDrawable.setStroke(10, Color.BLUE);
// gradientDrawable.setCornerRadius(10);
//1、2两个参数表示左上角,3、4表示右上角,5、6表示右下角,7、8表示左下角
let radiusArr = util.java.array("float", 8);
radiusArr[0] = 10;
radiusArr[1] = 20;
radiusArr[2] = 30;
radiusArr[3] = 40;
radiusArr[4] = 50;
radiusArr[5] = 60;
radiusArr[6] = 70;
radiusArr[7] = 80;
gradientDrawable.setCornerRadii(radiusArr);
gradientDrawable.setSize(50, 50);
view.setBackground(gradientDrawable);
}
function rndColor() {
return colors.rgb(random(0, 255), random(0, 255), random(0, 255));
}
function rndNum(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
网友评论