W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
版本要求:基礎(chǔ)庫(kù) 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">設(shè)置是否保持屏幕長(zhǎng)亮狀態(tài)</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">設(shè)置屏幕亮度</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: `當(dāng)前屏幕亮度:${res.brightness}`
});
}
})
}
});
Object 類型,屬性如下:
屬性 | 類型 | 必填 | 說(shuō)明 |
---|---|---|---|
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù)。 |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù)。 |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)。 |
版本要求:基礎(chǔ)庫(kù) 1.4.0 或更高版本,若版本較低,建議做 兼容處理。
設(shè)置屏幕亮度。
<!-- 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">設(shè)置是否保持屏幕長(zhǎng)亮狀態(tài)</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">設(shè)置屏幕亮度</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: `當(dāng)前屏幕亮度:${res.brightness}`
});
}
})
}
});
屬性 | 類型 | 必填 | 說(shuō)明 |
---|---|---|---|
brightness | Number | 是 | 需要設(shè)置的屏幕亮度,取值范圍 0-1。 |
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù)。 |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù)。 |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)。 |
版本要求:基礎(chǔ)庫(kù) 1.3.0 或更高版本,若版本較低,建議做 兼容處理。
設(shè)置是否保持屏幕長(zhǎng)亮狀態(tài)。僅在當(dāng)前小程序生效,離開(kāi)小程序后失效。
<!-- 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">設(shè)置是否保持屏幕長(zhǎng)亮狀態(tài)</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">設(shè)置屏幕亮度</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: `當(dāng)前屏幕亮度:${res.brightness}`
});
}
})
}
});
Object 類型,屬性如下:
屬性 | 類型 | 必填 | 說(shuō)明 |
---|---|---|---|
keepScreenOn | Boolean | 是 | 是否保持屏幕長(zhǎng)亮狀態(tài)。 |
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù)。 |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù)。 |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: