HarmonyOS鴻蒙動態設定背景漸變色
阿新 • • 發佈:2021-01-07
Button btn = (Button) findComponentById(ResourceTable.Id_tv1); //動態設定背景漸變色 ShapeElement shapeElement = new ShapeElement(); //設定漸變的起始結束方向 shapeElement.setGradientOrientation(ShapeElement.Orientation.LEFT_TO_RIGHT); RgbColor[] rgbColors = new RgbColor[2]; rgbColors[0] = RgbColor.fromArgbInt(0xFF0000E3); rgbColors[1] = RgbColor.fromArgbInt(0xFFB9B9FF); //設定漸變色 shapeElement.setRgbColors(rgbColors); //設定圓角(鴻蒙目前只有同時設定四個角,沒有單獨設定某個角的方法,如果有知道的可以下方評論) shapeElement.setCornerRadius(20); //設定到背景上 btn.setBackground(shapeElement);