Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17177] Android: AppCompat actionBar.hide() doesn't hide the actionbar prior to a window appearing

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2014-07-23T18:27:30.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.3.1, Release 3.4.0
Componentsn/a
Labelsandroid
ReporterAndrew Greenstreet
AssigneePing Wang
Created2014-06-16T23:59:05.000+0000
Updated2017-03-22T22:14:17.000+0000

Description

For example:
var window = Ti.UI.createWindow({
      title: "Title"
});

window.addEventListener("open", function() {
     window.activity.actionBar.hide();
});

window.add(Ti.UI.createLabel({
     text:"App Compat or just ignore Android < 4.0"
}));

window.open({
    opacity : 1,
    windowSoftInputMode: Titanium.UI.Android.SOFT_INPUT_ADJUST_RESIZE,
});
The action bar will appear for a short time before being hidden. This makes it impossible to make transparent overlay windows, that do not require an Action Bar, without making the app seem clunky and broken. Is is possible to make AppCompat optional or at least make navBarHidden : true work with AppCompat?

Comments

  1. Shuo Liang 2014-06-17

    I think this will help you: http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Android.ActionBar
  2. Andrew Greenstreet 2014-06-17

    Yep. That's the documentation. This is a "bug" in 3.3.0.RC. The issue isn't whether or not you can hide / control the ActionBar, the issue can you hide the ActionBar before the window appears on the device. In my testing so far, I cannot get a window to open without seeing the ActionBar for some small period of time. This is very undesirable side effect of moving to AppCompat.
  3. Shuo Liang 2014-06-18

    Oh ok, I see your problem. I will forward this ticket to engineer team, they will take care of this bug. Thank you for your case.
  4. Shuo Liang 2014-06-18

    I can reproduce this problem, the action will show up for 2 seconds before window appears. Studio 3.3.0 RC Android 4.2.2 Samsung Nexus
  5. Ingo Muschenetz 2014-06-18

    [~hpham], thoughts?
  6. Hieu Pham 2014-06-19

    You can hide the title bar via custom themes. It depends on which activity you wish to hide the title bar, here are some options and how to do it. First, create a custom theme file, i.e: myTheme.xml and put it in platform/android/res/values. Here's an example, note that this theme extends Theme.Titanium, which is our default theme for android application.
       <?xml version="1.0" encoding="utf-8"?>
       <resources>
       <style name="Theme.Titanium.NoTitle">
       		<item name="android:windowNoTitle">true</item>
       </style>
       
       </resources>
       
    1. If you want to hide the title bar for the root activity (the activity with the splash screen), you need to do something like this:
       <application>
       <activity android:name=".YourAppName" android:label="@string/app_name" android:theme="@style/Theme.Titanium.NoTitle" android:configChanges="keyboardHidden|orientation|screenSize">
       					<intent-filter>
       						<action android:name="android.intent.action.MAIN"/>
       						<category android:name="android.intent.category.LAUNCHER"/>
       					</intent-filter>
       				</activity>
       </application>
       
    2. If you want to hide title bar for windows without 'opacity' property, you can do this:
                   <application android:debuggable="true" android:theme="@style/Theme.Titanium.NoTitle"/>
       
    3. If you want to hide title bar for windows with 'opacity' property set, then do:
       <application>
       	   <activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/Theme.Titanium.NoTitle"/>
       </application>
       
       
    A useful tip would be to build the app once, go to build/android/AndroidManifest.xml and observe which activities are using what themes, then you can copy and paste blocks of activity code to your tiapp.xml and change the existing theme to your liking.
  7. Andrew Greenstreet 2014-06-21

    This is less than ideal as it is an all or nothing situation. I tried combining
       <activity android:name=".YourAppName" android:label="@string/app_name" android:theme="@style/Theme.Titanium.NoTitle" android:configChanges="keyboardHidden|orientation|screenSize">
       <intent-filter>
       <action android:name="android.intent.action.MAIN"/>
         <category android:name="android.intent.category.LAUNCHER"/>
         </intent-filter>
       </activity>
       <activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/Theme.Titanium.NoTitle"/>
       </application>
       
    And the app just gets stuck at the splash page. Changing the theme of TiTranslucentActivity to:
       <activity
        android:name="org.appcelerator.titanium.TiTranslucentActivity"
       		android:configChanges="keyboardHidden|orientation|screenSize"
       						android:theme="@style/Theme.AppCompat.Translucent.NoTitleBar"/>
       
    Seems to work. Although, the capability to mix and match windows with or without actionbars has effectively been removed from the framework. I'm curious why navbarHidden : true was removed as it seemed the most flexible way to deal with ActionBar visibility.
  8. Ingo Muschenetz 2014-06-22

    [~andrew@gstreetmedia.com] Thank you. Is it possible to give an example of how this is used in your application so we have a better understanding of the use case?
  9. Hieu Pham 2014-06-24

    Andrew, your coding sample uses 'opacity' when creating a window, therefore changing theme of TiTranslucentActivity should work. In the previous comment, I was just showing some examples of how to integrate your own custom themes for the various activities Titanium uses.
  10. Ping Wang 2014-06-26

    Windows with or without action bars can be created by applying different themes. Therefore a more elegant way to solve this problem is to support the "theme" property for windows. Already filed TIMOB-17222. Marking this ticket as resolved.
  11. Andrew Greenstreet 2014-07-23

    In the continuing fallout of deciding to go this route. If you create a window with no Titlebar, that also contains a textfield, you can crash the app by long presssing on the field. It results in the following error
        [ERROR] TiApplication: (main) [3068,24962] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 3.3.0,2014/07/22 11:24,787cd39
        [ERROR] TiApplication: java.lang.NullPointerException
        [ERROR] TiApplication:  at android.support.v7.app.ActionBarImplICS.getThemedContext(ActionBarImplICS.java:302)
        [ERROR] TiApplication:  at android.support.v7.app.ActionBarImplJB.getThemedContext(ActionBarImplJB.java:20)
        [ERROR] TiApplication:  at android.support.v7.app.ActionBarActivityDelegate.getActionBarThemedContext(ActionBarActivityDelegate.java:208)
        [ERROR] TiApplication:  at android.support.v7.app.ActionBarActivityDelegateICS.onActionModeStarted(ActionBarActivityDelegateICS.java:195)
        [ERROR] TiApplication:  at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onActionModeStarted(ActionBarActivityDelegateICS.java:359)
        [ERROR] TiApplication:  at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2711)
        [ERROR] TiApplication:  at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2619)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
        [ERROR] TiApplication:  at android.view.View.startActionMode(View.java:4752)
        [ERROR] TiApplication:  at android.widget.Editor.startSelectionActionMode(Editor.java:1805)
        [ERROR] TiApplication:  at android.widget.Editor.performLongClick(Editor.java:1036)
        [ERROR] TiApplication:  at android.widget.TextView.performLongClick(TextView.java:10110)
        [ERROR] TiApplication:  at android.view.View$CheckForLongPress.run(View.java:19410)
        [ERROR] TiApplication:  at android.os.Handler.handleCallback(Handler.java:733)
        [ERROR] TiApplication:  at android.os.Handler.dispatchMessage(Handler.java:95)
        [ERROR] TiApplication:  at android.os.Looper.loop(Looper.java:146)
        [ERROR] TiApplication:  at android.app.ActivityThread.main(ActivityThread.java:5487)
        [ERROR] TiApplication:  at java.lang.reflect.Method.invokeNative(Native Method)
        [ERROR] TiApplication:  at java.lang.reflect.Method.invoke(Method.java:515)
        [ERROR] TiApplication:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        [ERROR] TiApplication:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        [ERROR] TiApplication:  at dalvik.system.NativeStart.main(Native Method)
        
    This is because Android wants to open (in the ActionBar), the cut / paste / copy Toolbar. However, there isn't an ActionBar so the app will just crash.
  12. Ping Wang 2014-07-23

    Reopen to modify the fix version.
  13. Ping Wang 2014-07-23

    Hi [~andrew@gstreetmedia.com], I ran a simple test case but could not reproduce the crash you mentioned. Can you provide a sample to reproduce the bug? And what version of your Titanium SDK and what device do you use?
  14. Jelmer Jellema 2014-08-22

    So where we could just use 'navbarHidden: true' in SDK 3.2, we now have to hack ourself through all the Android stuff Titanium was supposed to hide from us? How is this better than 3.2?
  15. Ping Wang 2014-08-22

    [~jelmerjellema], in our default theme.xml, there already has been a theme which hides the nav bar, called "Theme.Titanium". So for SDK 3.3.1+, when creating a window, you can use
        theme: "Theme.Titanium"
        
    instead of 'navBarHidden: true'. [~bhatfield], can we document all the themes which already have been in the default theme.xml so users can easily use them?
  16. Jelmer Jellema 2014-08-25

    Right, I already thought so, reading theme.xml. But then again, it said the Titanium theme would be the default and the nav bar was still showing. I created a theme as written in the documentation, had to figure out where to put it (given I use Alloy), and changed the manifest. So, finally it was gone. Took me a while. My point being: this should not happen in between "there's a new version" style updates. It took me over 1 working day to get up and running again after thinking "sure, a new update, why not?".
  17. Ping Wang 2014-08-25

    For the predefined themes in Titanium, please refer this [guide| https://wiki.appcelerator.org/display/guides2/Android+Themes#AndroidThemes-TitaniumThemes].
  18. Jelmer Jellema 2014-08-26

    Yes, but the documentation says this: http://docs.appcelerator.com/titanium/3.0/#!/guide/Android_Action_Bar-section-36735509_AndroidActionBar-HidingtheActionBar
  19. Jelmer Jellema 2014-09-01

    This, just does not work. Actionbar still there. The solution given in the docs (making your own theme) does work, however not for transparent windows and the like. "Window": { backgroundColor: '#fff', navBarHidden: true, theme: "Theme.Titanium" }
  20. Michael Gangolf 2014-09-17

    any solution for transparent windows without an actionbar? As soon as I change the backgroundColor back to "transparent" the Actionbar is visible again. The window needs to be transparent.
  21. Ping Wang 2014-09-17

    Please refer to [this guide](http://docs.appcelerator.com/titanium/3.0/#!/guide/Android_Themes-section-34636181_AndroidThemes-TitaniumThemes) for the predefined themes. Transparent windows without an actionbar should be "Theme.AppCompat.Translucent.NoTitleBar".
  22. Michael Gangolf 2014-09-17

    ok, its working now. Had to switch to 3.4.0.v20140917120000 first. I've tried that before but then I saw my android-launcher (so when I opened the transparent window the normal window below it got transparent too). Now with 3.4.0.v20140917120000 its working as expeted
  23. Lee Morris 2017-03-22

    Closing ticket as duplicate and links to the related ticket have been provided above.

JSON Source