背景設(shè)置
設(shè)置組件的背景樣式。
說明:
開發(fā)前請(qǐng)熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
屬性
名稱 | 參數(shù)類型 | 描述 |
---|---|---|
background10+ | builder: [CustomBuilder], options?: {align?:[Alignment]} | builder:自定義背景。 align:設(shè)置自定義背景與組件的對(duì)齊方式。 同時(shí)設(shè)置了background,backgroundColor,backgroundImage時(shí),疊加顯示,background在最上層。**說明:**自定義背景渲染會(huì)有一定延遲,不能響應(yīng)事件,不能進(jìn)行動(dòng)態(tài)更新。該屬性不支持嵌套使用,不支持預(yù)覽器預(yù)覽。 |
backgroundColor | [ResourceColor] | 設(shè)置組件的背景色。 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
backgroundImage | src: [ResourceStr], repeat?: [ImageRepeat] | src:圖片地址,支持網(wǎng)絡(luò)圖片資源地址和本地圖片資源地址和Base64,不支持svg類型的圖片。 repeat:設(shè)置背景圖片的重復(fù)樣式,默認(rèn)不重復(fù)。當(dāng)設(shè)置的背景圖片為透明底色圖片,且同時(shí)設(shè)置了backgroundColor時(shí),二者疊加顯示,背景顏色在最底部。 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
backgroundImageSize | { width?: [Length], height?: [Length] } | [ImageSize] |
backgroundImagePosition | [Position] | [Alignment] |
backgroundBlurStyle9+ | value:[BlurStyle], options10+?:[BackgroundBlurStyleOptions] | 為當(dāng)前組件提供一種在背景和內(nèi)容之間的模糊能力。 value: 背景模糊樣式。模糊樣式中封裝了模糊半徑、蒙版顏色、蒙版透明度、飽和度、亮度五個(gè)參數(shù)。 options: 可選參數(shù),背景模糊選項(xiàng)。 該接口支持在ArkTS卡片中使用。 |
BackgroundBlurStyleOptions10+對(duì)象說明
名稱 | 參數(shù)類型 | 必填 | 描述 |
---|---|---|---|
colorMode | [ThemeColorMode] | 否 | 背景模糊效果使用的深淺色模式。 默認(rèn)值:ThemeColorMode.System |
adaptiveColor | [AdaptiveColor] | 否 | 背景模糊效果使用的取色模式。 默認(rèn)值:AdaptiveColor.Default |
scale | number | 否 | 背景材質(zhì)模糊效果程度。此參數(shù)為系統(tǒng)接口。 默認(rèn)值:1.0 取值范圍:[0.0, 1.0] |
示例
示例1
// xxx.ets
@Entry
@Component
struct BackgroundExample {
build() {
Column({ space: 5 }) {
Text('background color').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().width('90%').height(50).backgroundColor(0xE5E5E5).border({ width: 1 })
Text('background image repeat along X').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.backgroundImage('/comment/bg.jpg', ImageRepeat.X)
.backgroundImageSize({ width: '250px', height: '140px' })
.width('90%')
.height(70)
.border({ width: 1 })
Text('background image repeat along Y').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.backgroundImage('/comment/bg.jpg', ImageRepeat.Y)
.backgroundImageSize({ width: '500px', height: '120px' })
.width('90%')
.height(100)
.border({ width: 1 })
Text('background image size').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.width('90%').height(150)
.backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat)
.backgroundImageSize({ width: 1000, height: 500 })
.border({ width: 1 })
Text('background fill the box(Cover)').fontSize(9).width('90%').fontColor(0xCCCCCC)
// 不保準(zhǔn)圖片完整的情況下占滿盒子
Row()
.width(200)
.height(50)
.backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat)
.backgroundImageSize(ImageSize.Cover)
.border({ width: 1 })
Text('background fill the box(Contain)').fontSize(9).width('90%').fontColor(0xCCCCCC)
// 保準(zhǔn)圖片完整的情況下放到最大
Row()
.width(200)
.height(50)
.backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat)
.backgroundImageSize(ImageSize.Contain)
.border({ width: 1 })
Text('background image position').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.width(100)
.height(50)
.backgroundImage('/comment/bg.jpg', ImageRepeat.NoRepeat)
.backgroundImageSize({ width: 1000, height: 560 })
.backgroundImagePosition({ x: -500, y: -300 })
.border({ width: 1 })
}
.width('100%').height('100%').padding({ top: 5 })
}
}
示例2
// xxx.ets
@Entry
@Component
struct BackgroundBlurStyleDemo {
build() {
Column() {
Row() {
Text("Thin Material")
}
.width('50%')
.height('50%')
.backgroundBlurStyle(BlurStyle.Thin, { colorMode: ThemeColorMode.LIGHT, adaptiveColor: AdaptiveColor.DEFAULT, scale: 1.0 })
.position({ x: '15%', y: '30%' })
}
.height('100%')
.width('100%')
.backgroundImage($r('app.media.bg'))
.backgroundImageSize(ImageSize.Cover)
}
}
示例3
`HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿`
// xxx.ets
@Entry
@Component
struct BackgroundExample {
@Builder renderBackground() {
Column() {
Progress({value : 50})
}
}
build() {
Column() {
Text("content")
.width(100)
.height(40)
.fontColor("#FFF")
.position({x:50, y:80})
.textAlign(TextAlign.Center)
.backgroundColor(Color.Green)
}
.width(200).height(200)
.background(this.renderBackground)
.backgroundColor(Color.Gray)
}
}
審核編輯 黃宇
-
鴻蒙
+關(guān)注
關(guān)注
60文章
2620瀏覽量
44063
發(fā)布評(píng)論請(qǐng)先 登錄
鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【圖片邊框設(shè)置】 通用屬性

HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS的聲明式開發(fā)范式
鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【按鍵事件】

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【尺寸設(shè)置】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【邊框設(shè)置】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【透明度設(shè)置】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【顯隱控制】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【形狀裁剪】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【柵格設(shè)置】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【菜單控制】 通用屬性

鴻蒙ArkTS聲明式開發(fā):跨平臺(tái)支持列表【多態(tài)樣式】 通用屬性

評(píng)論