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 }); 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 -
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.