需要在Phonegap中使用Splashscreen调用函数

时间:2015-12-18 06:36:25

标签: cordova phonegap-plugins phonegap-build

我想在一个phonegap应用中的splashscreen上显示祝酒词。吐司应该用闪屏显示,而不是在它之后显示。

2 个答案:

答案 0 :(得分:2)

有趣的问题以及显示其他信息的好主意。我刚做了一个测试,它使用这个插件工作:

https://www.npmjs.com/package/cordova-plugin-splashscreen

https://www.npmjs.com/package/cordova-plugin-x-toast

在cordova deviceready-event之后,只需致电:

navigator.splashscreen.show();

然后你的祝酒词,这里是文档中的例子:

window.plugins.toast.showWithOptions(
            {
                message: "hey there",
                duration: "short",
                position: "bottom",
                addPixelsY: -40,  // (optional) added a negative value to move it up a bit (default 0)
                data: {} // (optional) pass in a JSON object here (it will be sent back in the success callback below)
            },
            // implement the success callback
            function(result) {
                if (result && result.event) {
                    console.log("The toast was tapped");
                    console.log("Event: " + result.event); // will be defined, with a value of "touch" when it was tapped by the user
                    console.log("Message: " + result.message); // will be equal to the message you passed in
                    console.log("data.foo: " + result.data.foo); // .. retrieve passed in data here
                } else {
                    console.log("The toast has been shown");
                }
            }
        );

答案 1 :(得分:0)

最简单的方法是将toast代码保留在设备就绪功能中。因此,当应用程序启动时,消息将随着它一起显示在屏幕上。

document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
       // write your code here
    }