问题描述
我正在使用钛合金来构建一个应用程序,我正在尝试用它的按钮创建一个标题栏,类似于联系人应用程序,如下所示:
本标题在中间和按钮中具有标题.
我一直在寻找一条在钛合金中这样做的方法,但我找不到任何东西.似乎这不是文档中的,我是否需要创建完全自定义的东西?
我试图在导航视图内添加一个按钮,但它不起作用 - 它出现了一个错误,说导航视图的子元素必须是一个窗口.
如果可能,我想使用合金创建此功能.
推荐答案
这很简单地创建.唯一的诀窍是用NavigationWindow缠绕窗口,因为您提到错误地提出了错误.导航栏按钮创建并连接在控制器中.据我所知,您无法在XML文件中创建它们.但是,通过使用$ .ui.create()方法您确保所有类和样式都将适用于它们.
index.html:
<Alloy> <NavigationWindow> <Window title="Contacts" id="contacts"> <SearchBar hintText="Search" /> <TableView /> </Window> </NavigationWindow> </Alloy>
index.js:
$.contacts.leftNavButton = $.UI.create('Button', { title: 'Groups' }); $.contacts.rightNavButton = $.UI.create('Button', { systemButton: Ti.UI.iPhone.SystemButton.ADD }); $.index.open();
index.tss:
"Window": { backgroundColor: "white", layout: "vertical", },
问题描述
I'm using Titanium Alloy to build an app and I'm trying to create a header bar with buttons in it, similar to the contacts app, as pictured below:
This header has the title in the middle and buttons either site.
I've been looking everywhere for a way to do this in Titanium but I can't find anything yet. It seems that this is not in the documentation, do I need to create something completely custom?
I have tried to add a button inside a navigation view, but it doesn't work - it comes up with an error saying that you the child element of a navigation view has to be a window.
If possible, I'd like to create this using Alloy.
推荐答案
That's pretty easy view to create. The only trick is to wrap Window with NavigationWindow as it was suggested in error you mentioned. NavBar buttons are created and attached in controller. As far as I remember, you can't create them in xml file. However by using $.UI.create() method you make sure that all classes and styles will apply to them, too.
index.html:
<Alloy> <NavigationWindow> <Window title="Contacts" id="contacts"> <SearchBar hintText="Search" /> <TableView /> </Window> </NavigationWindow> </Alloy>
index.js:
$.contacts.leftNavButton = $.UI.create('Button', { title: 'Groups' }); $.contacts.rightNavButton = $.UI.create('Button', { systemButton: Ti.UI.iPhone.SystemButton.ADD }); $.index.open();
index.tss:
"Window": { backgroundColor: "white", layout: "vertical", },