theme.md 2.6 KB
Newer Older
D
DCloud_LXH 已提交
1 2 3 4
## uni.setAppTheme(options) @setapptheme

<!-- UTSAPIJSON.setAppTheme.description -->

DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
5 6
<!-- UTSAPIJSON.setAppTheme.compatibility -->

D
DCloud_LXH 已提交
7 8
<!-- UTSAPIJSON.setAppTheme.param -->

shutao-dc's avatar
shutao-dc 已提交
9 10
<!-- UTSAPIJSON.setAppTheme.returnValue -->

shutao-dc's avatar
shutao-dc 已提交
11 12 13 14
```uts
uni.setAppTheme({
  theme: "auto",
  success: function() {
shutao-dc's avatar
shutao-dc 已提交
15
    console.log("设置appTheme为 auto 成功")
shutao-dc's avatar
shutao-dc 已提交
16 17
  },
  fail: function(e: IAppThemeFail) {
shutao-dc's avatar
shutao-dc 已提交
18
    console.log("设置appTheme为 auto 失败,原因:", e.errMsg)
shutao-dc's avatar
shutao-dc 已提交
19 20 21
  }
})
```
D
DCloud_LXH 已提交
22 23 24 25 26 27 28

<!-- UTSAPIJSON.setAppTheme.tutorial -->

## uni.onOsThemeChange(callback) @onosthemechange

<!-- UTSAPIJSON.onOsThemeChange.description -->

DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
29 30
<!-- UTSAPIJSON.onOsThemeChange.compatibility -->

D
DCloud_LXH 已提交
31 32
<!-- UTSAPIJSON.onOsThemeChange.param -->

shutao-dc's avatar
shutao-dc 已提交
33 34
<!-- UTSAPIJSON.onOsThemeChange.returnValue -->

shutao-dc's avatar
shutao-dc 已提交
35 36 37 38 39 40
```uts
//callbackId 用于注销监听
val callbackId = uni.onOsThemeChange((res: OsThemeChangeResult)=> {
    console.log("onOsThemeChange---", res.osTheme)
})
```
D
DCloud_LXH 已提交
41

shutao-dc's avatar
shutao-dc 已提交
42 43 44 45
<!-- UTSAPIJSON.onOsThemeChange.tutorial -->

**注意:**
+ android 平台 android版本 10 开始支持深色模式主题 `dark`,低于10不支持深色模式主题
D
DCloud_LXH 已提交
46 47 48 49 50

## uni.offOsThemeChange(id) @offosthemechange

<!-- UTSAPIJSON.offOsThemeChange.description -->

DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
51 52
<!-- UTSAPIJSON.offOsThemeChange.compatibility -->

D
DCloud_LXH 已提交
53 54
<!-- UTSAPIJSON.offOsThemeChange.param -->

shutao-dc's avatar
shutao-dc 已提交
55
<!-- UTSAPIJSON.offOsThemeChange.returnValue -->
shutao-dc's avatar
shutao-dc 已提交
56

shutao-dc's avatar
shutao-dc 已提交
57 58 59 60 61 62 63 64 65
```uts
val callbackId = uni.onOsThemeChange((res: OsThemeChangeResult)=> {
    console.log("onOsThemeChange---", res.osTheme)
})
...
...
//注销监听
uni.offOsThemeChange(callbackId)
```
shutao-dc's avatar
shutao-dc 已提交
66

shutao-dc's avatar
shutao-dc 已提交
67
<!-- UTSAPIJSON.offOsThemeChange.tutorial -->
D
DCloud_LXH 已提交
68 69 70 71 72

## uni.onAppThemeChange(callback) @onappthemechange

<!-- UTSAPIJSON.onAppThemeChange.description -->

DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
73 74
<!-- UTSAPIJSON.onAppThemeChange.compatibility -->

D
DCloud_LXH 已提交
75 76
<!-- UTSAPIJSON.onAppThemeChange.param -->

shutao-dc's avatar
shutao-dc 已提交
77 78
<!-- UTSAPIJSON.onAppThemeChange.returnValue -->

shutao-dc's avatar
shutao-dc 已提交
79 80 81 82 83 84
```uts
//callbackId 用于注销监听
val callbackId = uni.onAppThemeChange((res: AppThemeChangeResult) => {
  console.log("onAppThemeChange", res.appTheme)
})
```
D
DCloud_LXH 已提交
85 86 87 88 89 90 91

<!-- UTSAPIJSON.onAppThemeChange.tutorial -->

## uni.offAppThemeChange(id) @offappthemechange

<!-- UTSAPIJSON.offAppThemeChange.description -->

DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
92 93
<!-- UTSAPIJSON.offAppThemeChange.compatibility -->

D
DCloud_LXH 已提交
94 95
<!-- UTSAPIJSON.offAppThemeChange.param -->

shutao-dc's avatar
shutao-dc 已提交
96 97
<!-- UTSAPIJSON.offAppThemeChange.returnValue -->

shutao-dc's avatar
shutao-dc 已提交
98 99 100 101 102 103 104 105 106
```uts
val callbackId = uni.onAppThemeChange((res: AppThemeChangeResult) => {
  console.log("onAppThemeChange", res.appTheme)
})
...
...
//注销监听
uni.offAppThemeChange(this.appThemeChangeId)
```
D
DCloud_LXH 已提交
107 108 109 110 111

<!-- UTSAPIJSON.offAppThemeChange.tutorial -->

<!-- UTSAPIJSON.general_type.name -->

DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
112
<!-- UTSAPIJSON.general_type.param -->