如何在钛金属手机中打开没有模态属性的新窗口时显示标题/导航栏?

时间:2012-10-19 07:29:52

标签: javascript titanium titanium-mobile

我制作简单的钛移动应用程序。首先,当我按下某个按钮时,我想打开新窗口。当我使用模态窗口时,它可以显示标题栏,所以我可以在那里放回按钮,如下所示:

enter image description here

这是我的代码:

    var MainMenu = require('ui/common/option2/MainMenu');

    var mainMenuWindow = Titanium.UI.createWindow({
        title:'Main Menu',
        backgroundColor:'white',
        modal:true,
        navBarHidden:Ti.Platform.osname ==='android' ? true : false
    });

    var mainMenu = new MainMenu(mainMenuWindow);
    mainMenuWindow.add(mainMenu);

    mainMenuWindow.open();

但如果我清除modal:true标题栏未显示如下:

enter image description here

有没有人知道如何在没有模态的情况下打开新窗口时显示/添加标题栏?我已经尝试使用工具栏,但它真的很麻烦,因为我应该定义字体大小,甚至按钮的位置:(任何建议吗?非常感谢..

2 个答案:

答案 0 :(得分:4)

实际上在没有使用模态的情况下显示标题栏存在问题,所以这是调整。

您必须添加一个标签组并将窗口添加到其选项卡,并将“tabBarHidden”设置为该窗口的true。

运行应用程序时,您会看到标题栏。

这是它的示例代码

var tabGroup = Ti.UI.createTabGroup();

var win = Ti.UI.createWindow({
  backgroundColor:'#fff',
  tabBarHidden:true
});

var tab = Ti.UI.createTab({
   window: win,
  title: 'my win'
});

tabGroup.addTab(tab);

tabGroup.open();

上述解决方案适用于iOS。

对于Android,这里有诀窍:

将这些行添加到<app-project-dir>/platform/android/res/layout/titanium_tabgroup.xml文件中。

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp">

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:layout_weight="1"/>

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0"/>

</LinearLayout>

</TabHost>

答案 1 :(得分:-2)

您已将navBarHidden设为true。试试这个:

var mainMenuWindow = Titanium.UI.createWindow({
    title:'Main Menu',
    backgroundColor:'white',
    modal:true,
    navBarHidden: false // always show nav bar
});
相关问题