Loading...

让APP某一个页面保持屏幕常亮的方法


  • 船长

    https://git.merproject.org/mer-core/nemo-keepalive/tree/master

    有时候我们需要在某些页面让屏幕一直亮着,不要熄屏,这时候就需要它了

    • 添加依赖
      在spec或yaml中添加libkeepalive
    • 在qml中使用
    /* ------------------------------------------------------------------------- *
     * Copyright (C) 2014 Jolla Ltd.
     * Contact: Martin Jones <martin.jones@jollamobile.com>
     * 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了……?


  • 船长

    @天苯 可以学学,这东西跨平台,写客户端界面首选


登录后回复
 

与 旗鱼俱乐部 的连接断开,我们正在尝试重连,请耐心等待