Titanium中的android:back(设备后退按钮)事件不起作用 [英] android:back (device back button) event in Titanium not working

查看:66
本文介绍了Titanium中的android:back(设备后退按钮)事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事android应用程序开发.我正在使用Titanium studio进行开发.我创建了一个简单的应用程序.我想在应用程序中捕获设备后退按钮事件,因为我不想在Titanium中使用android默认选项卡.我正在创建自己的选项卡.我尝试了以下代码:

Hi i am working on android application development.I am using Titanium studio for development. I create a simple application.I want to capture the device back button event in my application because I don't want to user android default tabs in titanium.I am creating my own tabs.I tried following code :

:list.js

var expt = Titanium.UI.currentWindow; 
expt.addEventListener('android:back', function (e) 
{
    Ti.App.fireEvent('expt_back_event');
});

:app.js

Ti.App.addEventListener('expt_back_event',function(e)
{
    alert('hiiii in side event listener');
});

但是它不起作用而不是弹出窗口,因此关闭了我不想要的应用程序.有什么办法可以得到这个结果.

But its not working instead of giving pop-up it closed my application which I don't want. Is there any way to obtain this result.

推荐答案

您必须取消事件提示.

mainWindow.addEventListener('android:back', function(e) {
    e.cancelBubble = true;

    Ti.App.fireEvent('android_back_button');
});

这篇关于Titanium中的android:back(设备后退按钮)事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆