完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
在graphic 文件下编写了一个 渐变的资源文件,在layout 中引用不起作用,资源文件代码如下:
ohos:center_color="#68D33C" ohos:end_color="#37C231" ohos:start_color="#91E344" ohos:type="linear" ohos:use_level="false"/> 引用代码: ohos:width="200vp" ohos:background_element="$graphic:bt_green"/> |
|
相关推荐
3个回答
|
|
|
xml的方式搞不定。java代码的方式可以:
Button btn_rectangle = (Button) findComponentById(ResourceTable.Id_btn_rectangle); btn_rectangle.setBackground(shape1()); private ShapeElement shape1(){ ShapeElement shapeElement = new ShapeElement(); shapeElement.setShape(ShapeElement.RECTANGLE); //color关键值 RgbColor[] rgbColors = new RgbColor[]{ RgbColor.fromArgbInt(getColor(ResourceTable.Color_btn_start)), RgbColor.fromArgbInt(getColor(ResourceTable.Color_btn_center)), RgbColor.fromArgbInt(getColor(ResourceTable.Color_btn_end))}; shapeElement.setRgbColors(rgbColors); //线性变化:对应type="linear" shapeElement.setShaderType(ShapeElement.LINEAR_GRADIENT_SHADER_TYPE); //变化方向,从左到右:对应angle="0"(我理解的应该没错吧,你自己再调整一下) shapeElement.setGradientOrientation(ShapeElement.Orientation.LEFT_TO_RIGHT); return shapeElement; } { "color": [ { "name": "btn_start", "value": "#91E344" }, { "name": "btn_center", "value": "#68D33C" }, { "name": "btn_end", "value": "#37C231" } ] } |
|
|
|
|
|
直接通过xml文件定义shape也是可以的。不过现在ide没有提示,估计还没有正式发布吧。
xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:shape="rectangle"> ohos:colors="#91E344,#68D33C,#37C231"/> ohos:shader_type="linear_gradient" ohos:orientation="LEFT_TO_RIGHT"/> |
|
|
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
4681 浏览 0 评论
30765 浏览 0 评论
【润开鸿HH-SCDAYU800A开发板试用体验】+系统编译
1103 浏览 0 评论
【汇思博SEEK100开发板试用体验】记录DevEco Studio 中遇到的问题
1484 浏览 0 评论
【汇思博SEEK100开发板试用体验】在开发板鸿蒙OS搭建QT开发环境
1219 浏览 0 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 10:46 , Processed in 0.863341 second(s), Total 77, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
416