[TIMOB-11597] Android: Action bar displays differently based on launch orientation
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-10-31T23:41:04.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | 2012 Sprint 22 Core, 2012 Sprint 22 |
Components | Android |
Labels | n/a |
Reporter | Arthur Evans |
Assignee | Ping Wang |
Created | 2012-10-29T17:40:39.000+0000 |
Updated | 2017-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.
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}
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.
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.
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
in tiapp.xml. I also tested with a native Android project. The behavior is the same as described above. Mark the ticket as invalid.
Thanks for digging into this one!
Hi Ping, This is not working for me. When I build my project, the generated AndroidManfiest.xml shows:
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.
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
to the tiapp.xml.
OK, so for those viewers playing at home, here's the lowdown. The switching DOES work, in the following cases: Both the
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.
Closing ticket as invalid with reference to the above comments.