在HarmonyOS NEXT开发中关于开屏背景色?开屏背景色设置了 "startWindowBackground": "$color:spColor", 但是设计要求改成渐变色,请问怎么在module.json5里面吧startWindowBackground配成渐变色呢?
在HarmonyOS NEXT开发中关于开屏背景色?开屏背景色设置了 "startWindowBackground": "$color:spColor", 但是设计要求改成渐变色,请问怎么在module.json5里面吧startWindowBackground配成渐变色呢?
目前HarmonyOS NEXT的module.json5中,startWindowBackground
属性暂不支持直接配置渐变色参数。推荐采用以下两种替代方案:
方案一:XML布局方案
在resources/base/layout
目录新建布局文件(如:splash_screen.xml)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<gradient
ohos:startColor="#FF6B6B"
ohos:endColor="#4ECDC4"
ohos:angle="45"
ohos:type="linear"/>
</shape>
修改module.json5配置
"startWindowBackground": "$layout:splash_screen"
方案二:Drawable资源方案
在resources/base/graphic
目录新建渐变资源(如:gradient_background.xml)
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="120vp" height="120vp">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FF6B6B"/>
<stop offset="100%" stop-color="#4ECDC4"/>
</linearGradient>
</defs>
<rect width="100%" height="100%" fill="url(#gradient)"/>
</svg>
修改module.json5配置
"startWindowBackground": "$graphic:gradient_background"
注意事项:
可以通过colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]]设置渐变色