ts-universal-attributes-opacity.md 1.2 KB
Newer Older
Z
zengyawen 已提交
1 2 3
# Opacity


4 5
> **NOTE**
>
Z
zengyawen 已提交
6
> This attribute is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
7

Z
zengyawen 已提交
8

9
You can set the opacity of a component.
Z
zengyawen 已提交
10

Z
zengyawen 已提交
11 12

## Required Permissions
Z
zengyawen 已提交
13 14 15

None

Z
zengyawen 已提交
16

Z
zengyawen 已提交
17 18 19
## Attributes


20
| Name | Type | Default Value | Description |
Z
zengyawen 已提交
21
| -------- | -------- | -------- | -------- |
22
| opacity | number \| [Resource](../../ui/ts-types.md) | 1 | Opacity of a component. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent. |
Z
zengyawen 已提交
23 24 25 26


## Example

27 28 29

```ts
// xxx.ets
Z
zengyawen 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
@Entry
@Component
struct OpacityExample {
  build() {
    Column({ space: 5 }) {
      Text('opacity(1)').fontSize(9).width('90%').fontColor(0xCCCCCC)
      Text().width('90%').height(50).opacity(1).backgroundColor(0xAFEEEE)
      Text('opacity(0.7)').fontSize(9).width('90%').fontColor(0xCCCCCC)
      Text().width('90%').height(50).opacity(0.7).backgroundColor(0xAFEEEE)
      Text('opacity(0.4)').fontSize(9).width('90%').fontColor(0xCCCCCC)
      Text().width('90%').height(50).opacity(0.4).backgroundColor(0xAFEEEE)
    }
    .width('100%')
    .padding({ top: 5 })
  }
}
```

Z
zengyawen 已提交
48
![en-us_image_0000001256858385](figures/en-us_image_0000001256858385.gif)