支付宝小程序API 屏幕亮度
my.getScreenBrightness
版本要求:基础库 1.4.0 或更高版本,若版本较低,建议做 兼容处理。
获取屏幕亮度。
扫码体验
效果示例
示例代码
<!-- API-DEMO page/API/screen/screen.axml-->
<view class="page">
<view class="page-description">屏幕亮度 API</view>
<view class="page-section">
<view class="page-section-title">设置是否保持屏幕长亮状态</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">设置屏幕亮度</view>
<view class="page-section-demo">
<slider value="{{brightness}}" max="1" min="0" onChange="sliderChange" step="0.02"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">获取屏幕亮度</view>
<view class="page-section-demo">
<button type="primary" onTap="getBrightness">获取屏幕亮度</button>
</view>
</view>
</view>
// API-DEMO page/API/screen/screen.js
Page({
data: {
status: false,
brightness: 1,
},
onLoad() {
my.getScreenBrightness({
success: res => {
this.setData({
brightness: res.brightness
})
},
})
},
sliderChange(e) {
my.setScreenBrightness({
brightness: e.detail.value,
success: (res) => {
this.setData({
brightness: e.detail.value,
})
}
})
},
switchKeepScreenOn(e) {
my.setKeepScreenOn({
keepScreenOn: e.detail.value,
success: (res) => {
this.setData({
status: e.detail.value,
})
}
})
},
getBrightness() {
my.getScreenBrightness({
success: res => {
my.alert({
content: `当前屏幕亮度:${res.brightness}`
});
}
})
}
});
入参
Object 类型,属性如下:
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 否 | 接口调用成功的回调函数。 |
fail | Function | 否 | 接口调用失败的回调函数。 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
my.setScreenBrightness
版本要求:基础库 1.4.0 或更高版本,若版本较低,建议做 兼容处理。
设置屏幕亮度。
扫码体验
效果示例
示例代码
<!-- API-DEMO page/API/screen/screen.axml-->
<view class="page">
<view class="page-description">屏幕亮度 API</view>
<view class="page-section">
<view class="page-section-title">设置是否保持屏幕长亮状态</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">设置屏幕亮度</view>
<view class="page-section-demo">
<slider value="{{brightness}}" max="1" min="0" onChange="sliderChange" step="0.02"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">获取屏幕亮度</view>
<view class="page-section-demo">
<button type="primary" onTap="getBrightness">获取屏幕亮度</button>
</view>
</view>
</view>
// API-DEMO page/API/screen/screen.js
Page({
data: {
status: false,
brightness: 1,
},
onLoad() {
my.getScreenBrightness({
success: res => {
this.setData({
brightness: res.brightness
})
},
})
},
sliderChange(e) {
my.setScreenBrightness({
brightness: e.detail.value,
success: (res) => {
this.setData({
brightness: e.detail.value,
})
}
})
},
switchKeepScreenOn(e) {
my.setKeepScreenOn({
keepScreenOn: e.detail.value,
success: (res) => {
this.setData({
status: e.detail.value,
})
}
})
},
getBrightness() {
my.getScreenBrightness({
success: res => {
my.alert({
content: `当前屏幕亮度:${res.brightness}`
});
}
})
}
});
入参
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
brightness | Number | 是 | 需要设置的屏幕亮度,取值范围 0-1。 |
success | Function | 否 | 接口调用成功的回调函数。 |
fail | Function | 否 | 接口调用失败的回调函数。 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
my.setKeepScreenOn
版本要求:基础库 1.3.0 或更高版本,若版本较低,建议做 兼容处理。
设置是否保持屏幕长亮状态。仅在当前小程序生效,离开小程序后失效。
扫码体验
效果示例
示例代码
<!-- API-DEMO page/API/screen/screen.axml-->
<view class="page">
<view class="page-description">屏幕亮度 API</view>
<view class="page-section">
<view class="page-section-title">设置是否保持屏幕长亮状态</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">设置屏幕亮度</view>
<view class="page-section-demo">
<slider value="{{brightness}}" max="1" min="0" onChange="sliderChange" step="0.02"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">获取屏幕亮度</view>
<view class="page-section-demo">
<button type="primary" onTap="getBrightness">获取屏幕亮度</button>
</view>
</view>
</view>
// API-DEMO page/API/screen/screen.js
Page({
data: {
status: false,
brightness: 1,
},
onLoad() {
my.getScreenBrightness({
success: res => {
this.setData({
brightness: res.brightness
})
},
})
},
sliderChange(e) {
my.setScreenBrightness({
brightness: e.detail.value,
success: (res) => {
this.setData({
brightness: e.detail.value,
})
}
})
},
switchKeepScreenOn(e) {
my.setKeepScreenOn({
keepScreenOn: e.detail.value,
success: (res) => {
this.setData({
status: e.detail.value,
})
}
})
},
getBrightness() {
my.getScreenBrightness({
success: res => {
my.alert({
content: `当前屏幕亮度:${res.brightness}`
});
}
})
}
});
入参
Object 类型,属性如下:
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
keepScreenOn | Boolean | 是 | 是否保持屏幕长亮状态。 |
success | Function | 否 | 接口调用成功的回调函数。 |
fail | Function | 否 | 接口调用失败的回调函数。 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |