W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
解釋:獲取屏幕亮度。
Web 態(tài)說明:Web 態(tài)暫不支持獲取屏幕亮度功能,調(diào)用該 API 會觸發(fā) fail 回調(diào)。
Object object
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 |
---|---|---|---|---|
success | Function | 否 | 接口調(diào)用成功的回調(diào) | |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) | |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行) |
參數(shù)名 | 類型 | 說明 |
---|---|---|
value | Number | 屏幕亮度值,范圍 0~1,0 最暗,1 最亮。 |
<view class="wrap">
<view class="card-area">
<view class="display-area">
<view class="brightness-title">當(dāng)前屏幕亮度</view>
<view class="value">{{value/100}}</view>
</view>
</view>
<view class="card-area">
<view class="top-description border-bottom">設(shè)置屏幕亮度</view>
<slider min="0" max="100" value="{{value}}" step="1" class="slider" bindchanging="brightnessChange"></slider>
</view>
<view class="card-area">
<view class="item-scroll block">
<text class="switch-text">設(shè)置保持屏幕常亮</text>
<switch bindchange="keepScreenOn"></switch>
</view>
</view>
<view class="tip-week">注:屏幕亮度及屏幕常亮設(shè)置僅在當(dāng)前小程序生效,離開小程序后失效。</view>
</view>
Page({
data: {
value: 10
},
onLoad(e) {
swan.getScreenBrightness({
success: res => {
let value = res.value || 0.1;
value = (value * 100).toFixed(0);
this.setData('value', value);
},
fail: err => {
console.log('getScreenBrightness fail', err);
}
});
},
brightnessChange(e) {
const value = e.detail.value;
this.setData('value', value);
swan.setScreenBrightness({
value: parseFloat(value / 100),
success: () => {
console.log('setScreenBrightness success');
},
fail: err => {
console.log('setScreenBrightness fail', err);
}
});
},
keepScreenOn(e) {
swan.setKeepScreenOn({
keepScreenOn: e.detail.checked,
success: () => {
console.log('keepScreenOn success');
},
fail: err => {
console.log('keepScreenOn fail', err);
}
});
}
});
錯誤碼 | 說明 |
---|---|
1001 | 執(zhí)行失敗 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: