How to create popup window on android with titanium?

You must Login before you can answer or comment on any questions.

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

— asked 3 years ago by David Lee
0 Comments

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
});
 
infoWin.open({modal:true});
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
});
 
alertDialog.addEventListener('click',function(e){
    if (e.index == 0) {
        //code to execute when the user clicked Yes.
    }else{
        //code to execute when the user clicked No
    }
});
 
alertDialog.show();
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, Harald

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

    — commented 3 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 3 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({
            height:styles.ui.platformHeight-borderSpace,
            width:styles.ui.platformWidth-borderSpace,
            backgroundColor:'white',
            borderWidth:3,
            borderColor:'#336699',
            left:borderSpace/2,
            right:borderSpace/2,
            top:borderSpace/2,
            bottom:borderSpace/2,
            layout:'vertical'
        });
borderSpace is set based on how much smaller the popup should be.

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

    — commented 3 years ago by David Lee

  • borderRadisu dont work for Android as far as I know...

    — commented 3 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 w.open({modal:true}); but error alert box appeared and close the app to close. Thanks.

    — commented 3 years ago by David Lee

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!