screen
用于获取及设置屏幕亮度、方向的模块。
TIP
安卓修改屏幕亮度时,需要有系统配置写入权限
API
get
获取屏幕亮度
get(callback)
- @callback {Function}:执行完该操作后的回调函数。回调函数将收到一个Response对象
brightness {float}
:亮度的值为0-1
Demo
const screen = weex.requireModule('screen');
const modal = weex.requireModule('modal');
screen.get(function (res) {
modal.toast({
message: res.brightness
});
});
set
设置屏幕亮度
set(value, callback)
- @value {float}:亮度值0-1
- @callback {Function}:执行完该操作后的回调函数。回调函数将收到一个Response对象
brightness {float}
:返回设置后的亮度值0-1
Demo
const screen = weex.requireModule('screen');
const modal = weex.requireModule('modal');
screen.set(0.7, function (res) {
modal.toast({
message: res.brightness
});
});
getOrientation
获取当前屏幕方向
getOrientation(callback)
- @callback {Function}:执行完该操作后的回调函数。回调函数将收到一个Response对象
orientation {string}
:横屏:landscape,竖屏:portrait
Demo
const screen = weex.requireModule('screen');
const modal = weex.requireModule('modal');
screen.getOrientation(function (res) {
modal.toast({
message: res.orientation
});
});
lockOrientation
获取当前屏幕方向
lockOrientation(value, callback)
- @value {string}:横屏:landscape,竖屏:portrait
- @callback {Function}:执行完该操作后的回调函数。回调函数将收到一个Response对象
orientation {string}
:返回设置后的值,横屏:landscape,竖屏:portrait
Demo
const screen = weex.requireModule('screen');
const modal = weex.requireModule('modal');
screen.lockOrientation('landscape', function (res) {
modal.toast({
message: res.orientation
});
});