Search code examples
javascripttitaniumtitanium-mobile

Whats a simple way to get a text input Alertdialog box on an Android


I want to get the password. A simple text input dialog box. Any simple way to do this?

In iPhone it creates like this.

style : Ti.UI.iphone.AlertDialogStyle.SECURE_TEXT_INPUT

But in android how can I do thi??


Solution

  • Currently Appcelerator does not provide such facility. But you can do it in a simple way by using a view, textField and button as follows

    var vwAlert = Ti.UI.createView({
        backgroundColor : '#311919',
        width       : '90%',
        height      : '40%',
        layout      : 'vertical',
        borderRadius: 5
    }); 
    
    var lblMessage = Ti.UI.createLabel({
        text        : 'Alert',
        top         : 10,
        color       : 'white',
        font        : {fontWeight : 'bold', fontSize : '16'}
    });
    
    var textField = Ti.UI.createTextField({
        width       :  '90%',
        top         :  '20',
            passwordMask: true,
        hintText    : 'Enter your text here',
        borderStyle     : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
        returnKeyType   : Ti.UI.RETURNKEY_RETURN,
        maxLength       : 70
    });
    
    var btnOK = Ti.UI.createButton({
        title   : 'OK',
        width   : '43%',
        top     : '25',
        font    : {fontWeight : 'bold', fontSize : '16'}
    });
    
    vwAlert.add(lblMessage);
    vwAlert.add(textField);
    vwAlert.add(btnOK);
    

    The above view will look like an alert dialog box since it's customized one. This will do the trick :)