1.目前shape无法设置渐变色,可通过代码设置
2.工具类:

package com.cmmboy.xzwp.utils;import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.element.ShapeElement;
import ohos.app.AbilityContext;public class ShapeUtils {/*** 渐变色背景*/public static ShapeElement getButtonShape(AbilityContext context, float radius, int resStartId, int resEndId) {ShapeElement shapeElement = new ShapeElement();shapeElement.setCornerRadius(radius);shapeElement.setShape(ShapeElement.RECTANGLE);//color关键值RgbColor[] rgbColors = new RgbColor[]{RgbColor.fromArgbInt(context.getColor(resStartId)),RgbColor.fromArgbInt(context.getColor(resEndId))};shapeElement.setRgbColors(rgbColors);//线性变化:对应type="linear"shapeElement.setShaderType(ShapeElement.LINEAR_GRADIENT_SHADER_TYPE);//变化方向,从左到右:对应angle="0"shapeElement.setGradientOrientation(ShapeElement.Orientation.LEFT_TO_RIGHT);return shapeElement;}/*** 通过id获取View*/public static <T extends Component> T findById(AbilitySlice context, int id) {return (T) context.findComponentById(id);}}

2.设置

DirectionalLayout typeLayout1 = component.findComponentById(ResourceTable.Id_typeLayout1);
typeLayout1.setBackground(ShapeUtils.getButtonShape(this, 20, ResourceTable.Color_color_Type1_Start, ResourceTable.Color_color_Type1_End));

3.color.json

{"color": [{"name": "color_Black","value": "#FF1D1C1C"},{"name": "color_Green","value": "#1AA034"},{"name": "color_Type1_Start","value": "#4facfe"},{"name": "color_Type1_End","value": "#00f2fe"},{"name": "color_Type2_Start","value": "#43e97b"},{"name": "color_Type2_End","value": "#38f9d7"},{"name": "color_Type3_Start","value": "#b465da"},{"name": "color_Type3_End","value": "#ee609c"},{"name": "color_Type4_Start","value": "#f83600"},{"name": "color_Type4_End","value": "#f9d423"},{"name": "color_Type5_Start","value": "#5271C4"},{"name": "color_Type5_End","value": "#ECA1FE"},{"name": "color_Type6_Start","value": "#0acffe"},{"name": "color_Type6_End","value": "#495aff"},{"name": "color_Type7_Start","value": "#473B7B"},{"name": "color_Type7_End","value": "#30D2BE"}]
}

鸿蒙 background_element设置渐变色相关推荐

  1. 03.鸿蒙HarmonyOS卡片 状态栏透明和代码设置渐变色

    1.状态栏透明和去掉标题栏 状态栏透明: WindowManager.getInstance().getTopWindow().get().addFlags(WindowManager.LayoutC ...

  2. html设置渐变色背景图片,css中渐变色作为背景图来使用总结

    qt中使用样式设置渐变色背景setStyleSheet()函数设置背景的前期是设置的窗口控件有父窗口ui.widget->setStyleSheet("background-color ...

  3. Android如何设置渐变色背景 渐变shape

    Android如何设置渐变色背景 Android开发过程中,会用到android:backgroud属性来设置背景的颜色,一般情况下我们直接设置一个类似#FFFF0000的值代表是背景颜色,如果想设置 ...

  4. qt 使用样式设置渐变色背景

    qt中使用样式设置渐变色背景 setStyleSheet()函数设置背景的前期是设置的窗口控件有父窗口 ui.widget->setStyleSheet("background-col ...

  5. python渐变色代码_使用python画图怎么设置渐变色

    Python中渐变的实现: 使用turtle库画一条渐变的蛇的代码:from turtle import * setup(500, 400, 200, 200) penup() fd(-250) pe ...

  6. flutter Container设置渐变色

    不得不说flutter在ui方面确实强大,可能用Android比较懒吧,下面说一下flutter中的Container设置渐变色,主要是在decoration里面进行设置. 其实Container这个 ...

  7. Echarts柱状图设置渐变色

    一.前言 本文针对react,在react项目中使用echarts 二.前期准备 安装依赖 npm i echarts --save 三.代码注释以及效果 案例一: import React, { u ...

  8. 前端通过值设置渐变色

    可以使用 CSS 的 background 属性来设置渐变色.具体方法如下: 在 CSS 中添加 background 属性,并设置为渐变色. .your-element {background: l ...

  9. Canvas画图设置渐变色

    1.线形图设置填充色为渐变色方法: /*** Draws the provided path in filled mode with the provided drawable.** @param c ...

  10. Swift学习之:设置渐变色

    在开发中,常常有这样的需求:给button添加渐变色.给label添加渐变色等等,因此只需要写一个UIView的类扩展,这些继承自UIView的类需要用的时候就能直接调用了. 代码如下: extens ...

最新文章

  1. python生成pdf报表_用python的reportlab库生成PDF报表
  2. sql server 的 money类型
  3. linux kernel 2.6.36 编译升级
  4. 人工神经网络_图像加载(数据挖掘入门与实践-实验10)
  5. Mybatis生成器插件扩展,定制方法生成,list参数生成
  6. scope参数错误或没有scope权限_SSM 单体框架 - 前端开发:用户和权限模块
  7. Magento教程 25:如何修改系统发送的通知信件?
  8. 【高并发】JUC中的循环栅栏CyclicBarrier的6种使用场景
  9. 点焊机器人焊接超时_「技术帖」FSW点焊技术在车身铝薄板焊接中的应用
  10. (亲测无坑)Centos7.x使用kubeadm安装K8s集群1.15.0版本
  11. 做为程序员,我到底在恐慌什么
  12. ASP.NET页面生命周期和asp.net应用程序生命周期
  13. 什么是HD , HDTV , BD(Blu-Ray) , HDDVD
  14. linux中怎么卸载桌面图标,如何从Ubuntu 18.04桌面上删除垃圾桶图标
  15. python实现——40W告警日志分析(上)
  16. oracle官网(中文)
  17. 几行烂代码,用错 Transactional,我赔了16万。
  18. 叮当健康明日港股上市:拟募资3.4亿港元 单季期内亏损4亿
  19. 微型计算机3月2017,2017年3月计算机一级《MS Office》巩固试题及答案
  20. Easyui数据表格合并单元格

热门文章

  1. python迷宫地图代码_python实现的生成随机迷宫算法核心代码分享(含游戏完整代码)...
  2. 数学建模国赛编程手必备工具
  3. Python字典的索引
  4. 计算机二级河南2020年12月报名时间,2020年3月河南省洛阳市计算机二级报名时间|网上报名入口【12月16日9:00开通】...
  5. 工程师思维的核心 |《转向:用工程师思维解决商业难题》
  6. [爬虫项目]猫眼电影TOP100
  7. matlab显示大图像
  8. 如何应对微信群舆情?
  9. CSDN博客图片服务器异常的艰辛排查与处理-上传文件时发生 HTTP 错误(错误代码:502)的解决办法
  10. 多边形的定义为什么要强调封闭图形_11.3.1 多边形讲解.ppt