Reputation: 2547
Action bar navigation tabs are merged in the action bar when going into landscape mode, so I defined a values-land
folder with a colors.xml
file where I set the appropriate background color and text color for the merged tabs. Long story short:
When i launch the app starting from landscape mode instead, and then changing to portrait, this is what I get:
the activity starts with the correct colors for landscape, as defined by me invalues-land/colors.xml
Only the tab's text color changes accordingly to my instructions.
The activity has launchMode="singleTask"
(which is mandatory for my case), but even with launchMode="standard"
the problem persists. I'm starting to think this is an API bug... Is there any workaround for this, like some way to force the redrawing of the action bar?
edit: my <activity>
tag:
<activity
android:name="com.rocca.controlloSpese.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0
Views: 644
Reputation: 2547
after deeper research and a few attempts, I found out what it was. When switching to landscape mode, the system looks for "-land" qualifiers and updates the views accordingly, like everybody knows. Therefore it updates my tab's text color because it finds a values-land/
directory in which there is a colors.xml
file with the specific colors.
The tabs' background is defined by drawables and I put them in the drawable
directory, because they are the same shape both for landscape and portrait, only colors change. So there is no drawable-land
directory, but this means that the system will not redraw the backgrounds and will recycle them, missing the fact that inside those drawables there are references to values that must change. The solution was to add a drawable-land
directory with a copy of the background drawables, so that the system will know that it must redraw the views. It will redraw the same views, but at least it will use the different colors.
Upvotes: 0
Reputation: 8866
It seems like you've set up the Android manifest such that the activity isn't destroyed during rotations. Unless you have a strong case to do that, you should let the activity be destroyed and recreated when rotating.
Upvotes: 1