How to create popup window on android with titanium?

May I know how can I create a popup window in android with titanium? It is just like an alert box, without button and the layout can be customized. It will close when back button on phone is pressed. Thank you.

Ti:1.6, Android 2.2

2 Answers

  • Hi David,

    I believe you can achive what you want with this code:

    var infoWin = Titanium.UI.createWindow({
        backgroundColor: '#FFFFFF',
        top: 0,
        left: 0,
        opacity: 1,
        zIndex: 100

    You can add buttons, text and images to this window as you wish, even a button which calls infoWin.close() instead of using the back button on your device.

    If you are looking for a normal alert, you can use this code:

    var alertDialog = Titanium.UI.createAlertDialog({
        title: 'Are you sure?',
        message: 'Do you want to do this?',
        buttonNames: ['Yes','No'],
        cancel: 1
        if (e.index == 0) {
            //code to execute when the user clicked Yes.
            //code to execute when the user clicked No

    This should pop a standard alert dialig in Android for you where you can check what the user did answer. The number of buttons are optional I think.

    You can ofcourse omit the dialog listener, and use the alert for information only.

    Hope this helps,

    — answered 5 years ago by Harald Sakshaug
    • Herald thanks for the input. May I know how to make border-radius for window?

      — commented 5 years ago by David Lee
    • I dont think border radius for Android works… Usually when I port my iPhone apps to Android, border, borderradius and such are the first which have to be removed…

      — commented 5 years ago by Harald Sakshaug
  • To create a true window that looked like a popup (e.g. didn't fully cover the other window) - I used the following code:

            var w = Titanium.UI.createWindow({

    borderSpace is set based on how much smaller the popup should be.

    — answered 5 years ago by Frank A
    • Thanks for the answer Frank. May I know how to make border radius for window?

      — commented 5 years ago by David Lee
    • borderRadisu dont work for Android as far as I know…

      — commented 5 years ago by Harald Sakshaug
    • how to make this window close with the back button and go back to th previous window? I have tried but it failed. It closes the window that open the new window too. I have tried to add{modal:true}); but error alert box appeared and close the app to close. Thanks.

      — commented 5 years ago by David Lee
    • When I open a window modally, it do close using the Back button on my Android.

      However, I do run my app on a different .js file than app.js.
      It is not so important to have a new window with its own js file in iPhone, but on Android this is needed to get the Window to have a proper activity. My is by this a kickstarter to open main.js which holds the application. (Pastie of a typical app.js

      In this main.js you write your application, and your base window then is a true Android activity. Perhaps this is needed for the modal window spawn from the main.js to close using the back button?

      In main.js you can access the base window using: var appWin = Titanium.UI.currentWindow;

      (You can even find the new activity as a property from the appWin variable as appWin.activity)

      Hope this helps,

      — commented 5 years ago by Harald Sakshaug