支付寶小程序API 屏幕亮度

2020-09-15 11:47 更新

my.getScreenBrightness

版本要求:基礎(chǔ)庫(kù) 1.4.0 或更高版本,若版本較低,建議做 兼容處理

獲取屏幕亮度。

掃碼體驗(yàn)

屏幕亮度qr.jpeg

效果示例

設(shè)置屏幕亮度.gif

示例代碼

<!-- 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}`
        });
      }
    })
  }
});

入?yún)?/h4>

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í)行)。

my.setScreenBrightness

版本要求:基礎(chǔ)庫(kù) 1.4.0 或更高版本,若版本較低,建議做 兼容處理

設(shè)置屏幕亮度。

掃碼體驗(yàn)

屏幕亮度qr.jpeg

效果示例

setscreenbrightness.PNG

示例代碼

<!-- 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}`
        });
      }
    })
  }
});

入?yún)?/h4>
屬性 類型 必填 說(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í)行)。

my.setKeepScreenOn

版本要求:基礎(chǔ)庫(kù) 1.3.0 或更高版本,若版本較低,建議做 兼容處理。

設(shè)置是否保持屏幕長(zhǎng)亮狀態(tài)。僅在當(dāng)前小程序生效,離開(kāi)小程序后失效。

掃碼體驗(yàn)

屏幕亮度qr.jpeg

效果示例

屏幕亮度.gif

示例代碼

<!-- 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}`
        });
      }
    })
  }
});

入?yún)?/h4>

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í)行)。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)