Titanium: How to hide the actionBar in a non-Alloy

2019-08-28 22:37发布

问题:

I have no problem hiding the action bar in an Alloy project. However, how do I do this in a non-Alloy project?

I tried this:

win.activity.actionBar.hide();

But it doesn't work.

回答1:

Via win.activity.actionBar.hide(); you can only hide the Action Bar when your window is finally opened. The main disadvantage is that sometimes you can see the Action Bar for a few milliseconds, because the window is initially created with Action Bar.

Since Titanium SDK 4.2.0 there are 4 predefined themes to hide the Action Bar:

Theme.AppCompat.NoTitleBar

Theme.AppCompat.NoTitleBar.Fullscreen

Theme.AppCompat.Translucent.NoTitleBar

Theme.AppCompat.Translucent.NoTitleBar.Fullscreen

see http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes-section-34636181_AndroidThemes-TitaniumThemes

Besides globally setting the theme in TiApp.xml (see Wang Dan's answer) one can hide the Action Bar via theme property of Ti.UI.Window.

var win = Ti.UI.createWindow({
    // ...
    theme: "Theme.AppCompat.NoTitleBar"
});

Note that this is a creation-only property, so win.theme = "Theme.AppCompat.NoTitleBar"; does not work.



回答2:

<android xmlns:android="http://schemas.android.com/apk/res/android">            
    <manifest>
        <application android:theme="@style/Theme.AppCompat.Translucent.NoTitleBar.Fullscreen"></application>
    </manifest>
</android>

Add this to TiApp.xml