Appcelerator Titanium Android 登录并转到选项卡

Posted

技术标签:

【中文标题】Appcelerator Titanium Android 登录并转到选项卡【英文标题】:Appcelerator Titanium Android Login and go to tab 【发布时间】:2014-03-08 07:21:44 【问题描述】:

您好,我需要创建一个使用 android 系统的应用程序,然后登录,因为您拥有正确的凭据以转到带有选项卡的窗口。

我在 app.js 中有这个用于身份验证的代码,它现在可以正常工作,但我还没有设法创建选项卡的结构。

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();

【问题讨论】:

【参考方案1】:

您可以从新的项目选项中创建一个默认的选项卡式应用程序。这将向您展示如何构建选项卡式应用程序。您可以重命名 JS 文件并将它们复制到您当前的项目中。将选项卡式窗口应用程序中的窗口打开调用插入成功的身份验证函数并打开它。该窗口应在您之前的带有验证码的窗口上方打开。

【讨论】:

以上是关于Appcelerator Titanium Android 登录并转到选项卡的主要内容,如果未能解决你的问题,请参考以下文章

使用 Titanium appcelerator 进行游戏开发

iOS、Appcelerator Titanium 和外部附件框架

iOS LocationManager 未更新位置(Titanium Appcelerator 模块)

Appcelerator Titanium 中面向 OOP 的 CommonJS

如何在Android中使用Appcelerator Titanium构建Oauth 2.0

Appcelerator Titanium 中的自定义通知视图