简体   繁体   中英

Appcelerator Titanium Android Login and go to tab

Hi I need to create an application that uses Android system and then login as you have the correct credentials to go to a window with tabs.

I have this code for authentication in app.js, it works fine for now but I have not managed to create the structure of tabs.

var win = Ti.UI.createWindow({
    backgroundColor: '#096594', 
    title: 'ACCESS CONFIG', 
    layout:'vertical',
    navBarHidden:true,
    fullscreen:false, 
     exitOnClose:true
});

var my_navbar = Ti.UI.createLabel({
    height:20,
    backgroundColor:'#989898',
    color:'#fff',
    text:'  ACCESS CONFIG',
    top:0,
    width:'100%',
    font:{fontSize:11,fontWeight:'normal'},
    marginleft:10
});
win.add(my_navbar);

win.add(Ti.UI.createLabel({
    top:10, 
    height:15, 
    left:10, 
    right:5,
    color:'#fff',
    textAlign:'left',
    text:'Usuario: [Userid]', 
    font:{fontSize:12},
    bottom:5
}));

var txtUserid = Ti.UI.createTextField({
    value:'1',
    hintText:'user ID',
    height:35, 
    left:5, 
    right:5,
    font:{fontSize:12},
    color:'#a2a2a2',
    borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED 
}); 
win.add(txtUserid);

win.add(Ti.UI.createLabel({
    top:2, 
    height:17, 
    left:10, 
    right:5,
    color:'#fff',
    textAlign:'left',
    text:'Name: [Login]', 
    font:{fontSize:12},
    bottom:5
}));

var txtLogin = Ti.UI.createTextField({
    value:'M',
    hintText:'Username',
    height:35, 
    left:5, 
    right:5,
    font:{fontSize:12},
    color:'#a2a2a2',
    borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED 
}); 
win.add(txtLogin);  

win.add(Ti.UI.createLabel({
    top:2, 
    height:17, 
    left:10, 
    right:5,
    color:'#fff',
    textAlign:'left',
    text:'Password: [Password]', 
    font:{fontSize:12},
    bottom:5
}));

var txtPassword = Ti.UI.createTextField({
    value:'111',
    hintText:'Contraseña',
    passwordMask:true,
    height:35, 
    left:5, 
    right:5,
    font:{fontSize:12},
    color:'#a2a2a2',
    borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED 
}); 
win.add(txtPassword);

win.add(Ti.UI.createLabel({
    top:10,
    height:0, 
    left:5, 
    right:5,
    color:'#000',
    textAlign:'left',
    text:'Authentication Url:', 
    font:{fontSize:18}
    }));

var txtUrl = Ti.UI.createTextField({
    value:'http://',
    hintText:'Url to connect with data',
    height:0, left:5, right:5,
    borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED 
}); 
win.add(txtUrl);


var yesButton = Ti.UI.createButton({
    title:'Connect with DATA', 
    top:5, 
    height:37, 
    left:85, 
    right:85,
    color:'#fff',
    backgroundColor:'#406a83',
    borderColor:'#688a9d',
    borderWidth:1,
    borderRadius:5,
    borderStyle:Ti.UI.INPUT_BORDERSTYLE_BEZEL   
});
win.add(yesButton);


yesButton.addEventListener('click', clickYesButton);

function clickYesButton(e) {
    var button = e.source;
    var xhr=Titanium.Network.createHTTPClient();   
    xhr.onerror = function(e){alert('Error: '+e.error);};
    xhr.onload = function() {alert(this.responseText);};
    xhr.open("POST",txtUrl.value);//ADD your URL
    var param={"userid":txtUserid.value,"login":txtLogin.value,"password":txtPassword.value};
    Ti.API.info('Params'+JSON.stringify(param));
    xhr.send(param);
}

win.open();

You can create a default tabbed-application from the new project options. This will show you how a tabbed application is built. You could rename the JS files and copy them to your current project. Insert the window open call from the tabbed-window application into your successful authentication function and open it. The window should open over the top of your previous window with the authentication code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM