让APP某一个页面保持屏幕常亮的方法
-
https://git.merproject.org/mer-core/nemo-keepalive/tree/master
有时候我们需要在某些页面让屏幕一直亮着,不要熄屏,这时候就需要它了
- 添加依赖
在spec或yaml中添加libkeepalive
- 在qml中使用
/* ------------------------------------------------------------------------- * * Copyright (C) 2014 Jolla Ltd. * Contact: Martin Jones <[email protected]> * License: BSD * ------------------------------------------------------------------------- */ import QtQuick 2.0 import Sailfish.Silica 1.0 import Nemo.KeepAlive 1.1 ApplicationWindow { property var startTime property var currentTime initialPage: Component { Page { KeepAlive { id: keepAlive } Timer { id: timer property int count interval: 1000 repeat: true onTriggered: { ++count currentTime = new Date() } } Column { width: parent.width spacing: Theme.paddingLarge anchors.centerIn: parent TextSwitch { text: "Keep Alive" anchors.horizontalCenter: parent.horizontalCenter onCheckedChanged: { startTime = new Date() currentTime = new Date() timer.count = 0 timer.restart() keepAlive.enabled = checked } } Label { anchors.horizontalCenter: parent.horizontalCenter text: "Duration: " + Math.round((currentTime.getTime() - startTime.getTime())/1000) } Label { anchors.horizontalCenter: parent.horizontalCenter text: "Timer triggered: " + timer.count } } Component.onCompleted: { startTime = new Date() currentTime = new Date() timer.start() } } } }
- 添加依赖
-
也许该试着学学qml了……?
-
@天苯 可以学学,这东西跨平台,写客户端界面首选