简体   繁体   中英

ActionBarSherlock Change Tab Text Color on Orientation Change

I have an ActionBar set up with ActionBarSherlock. I need to have a different tab text color set when the app is in portrait and landscape. When the tabs are in portrait mode the text should be a light grey, like this:

人像标签

When the orientation is landscape, the tab text color should be white (#FFFFFF). However, when the orientation is shifted to landscape the text looks like this:

风景标签

Again, I need to have the text color for the tab, when in landscape, white (#FFFFFF). I'm using the Light.DarkActionBar theme and setting the text color via the style as shown below.

In the /values folder

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Example.Theme.Default" parent="@style/Theme.Sherlock.Light.DarkActionBar">

        <item name="actionBarTabTextStyle">@style/Example.ActionBar.TabTextStyle</item>
        <item name="android:actionBarTabTextStyle">@style/Example.ActionBar.TabTextStyle</item>

    </style>

    <style name="Example.ActionBar.TabTextStyle"  parent="Widget.Sherlock.ActionBar.TabText">
        <item name="android:textColor">#585858</item>
    </style>

</resources>

When I rotate the device, the text stays dark, which is expected. I decided to fix this with resource modifiers and I created a new resource folder with the -land modifier under the values-land folder that had the new tab text style for when in landscape, as shown below.

In the /values-land folder

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Example.ActionBar.TabTextStyle"  parent="Widget.Sherlock.ActionBar.TabText">
        <item name="android:textColor">#FFFFFF</item>
    </style>

</resources>

At this point I expect the text to change color if I rotate the device. This does not happen . However ... if I go back to the Android homescreen place the device into landscape and then start the app , the correct resource styles is used (the tab text is white). If I rotate it back to portrait, it stays white. I expect it to go back to the darker color (#585858)

How can I get the text color to change on the tabs on screen orientation? It seems like Android or the ActionBar is ignoring the orientation change and not looking up the styles again. Anyone have any idea?

It sounds like you have android:configChanges="keyboardHidden|orientation" (or something similar) in your manifest. If you remove this, then it should change color on rotation. It will also cause the activity to be re-loaded on rotation, so make sure you handle that appropriately as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM