Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11597] Android: Action bar displays differently based on launch orientation

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-10-31T23:41:04.000+0000
Affected Version/sRelease 3.0.0
Fix Version/s2012 Sprint 22 Core, 2012 Sprint 22
ComponentsAndroid
Labelsn/a
ReporterArthur Evans
AssigneePing Wang
Created2012-10-29T17:40:39.000+0000
Updated2017-03-22T20:52:51.000+0000

Description

The Action bar doesn't appear to handle orientation changes correctly. For example, if I specify an action item (menu item) with an icon and
showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS|Ti.Android.SHOW_AS_ACTION_WITH_TEXT,
The text shows up only if the app is launched in landscape orientation, and doesn't go away if the app is rotated into portrait orientation. On the other hand, if I launch the app in portrait, only the icon is displayed, even when I rotate into landscape. On a related topic, the app icon is displayed larger when I launch in landscape mode. It appears that we use two different sizes, one for the stacked action bar and one for the ordinary portrait-mode action bar. I'm not sure if this behavior is correct in the first place--I can't see a reference to it in the Android docs. However, both versions seem to be scaled differently based on whether it's launched in portrait or landscape, which is definitely wrong.

Comments

  1. Shannon Hicks 2012-10-29

    The behavior of the title showing or not when in portrait seems to be a proper behavior. From http://developer.android.com/guide/topics/ui/actionbar.html : {quote}Note: The "withText" value is a hint to the action bar that the text title should appear. The action bar will show the title when possible, but might not if an icon is available and the action bar is constrained for space.{quote}
  2. Arthur Evans 2012-10-30

    Yes, that behavior is correct--what's not correct is that it's not updating correctly when orientation changes. If you launch in landscape, you ALWAYS have the text, if you launch in portrait, you NEVER have the text. So it seems like there's something that we need to refresh when we change orientations (or else this is a bug in Android). Testing the built-in Google apps, NONE of them seem to follow the documented behavior. Settings, Notes, Gmail--wherever they use text with action items, they seem to use it consistently in both landscape and portrait. Maybe it'd be different on a different device, but it doesn't seem like they're following their own design guidelines.
  3. Shannon Hicks 2012-10-30

    I was testing on my Galaxy Nexus running 4.1. I just took the tabbed application template project, and added the menu from the ActionBar JIRA ticket. Then I added an icon, and tweaked from there.
  4. Ping Wang 2012-10-31

    On Titanium, the property android:configChanges is set to "keyboardHidden|orientation|screenSize" by default for targetSdkVersion >= 13. Based on the Android [doc](http://developer.android.com/guide/topics/resources/runtime-changes.html): {quote} Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. {quote} this setting makes the app not to re-layout when orientation is changed. If we want the app to re-layout when changing the orientation, we can set
       <activity android:configChanges="keyboardHidden|orientation" android:name="xxxx"/>
       
    in tiapp.xml. I also tested with a native Android project. The behavior is the same as described above. Mark the ticket as invalid.
  5. Shannon Hicks 2012-10-31

    Thanks for digging into this one!
  6. Arthur Evans 2012-11-01

    Hi Ping, This is not working for me. When I build my project, the generated AndroidManfiest.xml shows:
       <activity android:configChanges="keyboardHidden|orientation" 
       
    I tried manually specifying this in my tiapp.xml as well, but it didn't solve the problem. The action item doesn't change its appearance on rotation.
  7. Ping Wang 2012-11-01

    Hi Arthur, in which activity did you set android:configChanges="keyboardHidden|orientation"? I think for the example you sent to me, you need to add
       <activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiActivity"/>
       
    to the tiapp.xml.
  8. Arthur Evans 2012-11-02

    OK, so for those viewers playing at home, here's the lowdown. The switching DOES work, in the following cases: Both the element and the launcher activity have to be declared with an action bar theme, such as "@android:style/Theme.Holo". TiActivity (and possibly also TiTranslucentActivity) need to be set to *not* handle the screenSize config change, like so:
       <activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiActivity"/>
       
    This results in Android restarting the activity on orientation change. The bad news: this results in the original window being torn down and recreated, with a noticeable pause during which you can see whatever was under the current window (the desktop, another app, etc). I don't think we can recommend this course of action to users; it's a terrible user experience, and it occurs whether the app is native or Titanium. So I'm going to create a new doc ticket recommending that users do *not* use SHOW_AS_ACTION_WITH_TEXT, but instead create an actionView if they want to display both text and icon. If the application is inherently portrait-only or landscape-only, they can safely use SHOW_AS_ACTION_WITH_TEXT -- but otherwise the user experience is unacceptable. The interesting thing is that showAsAction: SHOW_AS_ACTION_IF_ROOM is recalculated on reorientation--that is, the number of action items shown changes when moving from portrait to landscape and back.
  9. Lee Morris 2017-03-22

    Closing ticket as invalid with reference to the above comments.

JSON Source