简体   繁体   English

ActionBarSherlock更改选项卡上方向的文本颜色更改

[英]ActionBarSherlock Change Tab Text Color on Orientation Change

I have an ActionBar set up with ActionBarSherlock. 我有一个设置为ActionBarSherlock的ActionBar。 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). 当方向为横向时,选项卡文本颜色应为白色(#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). 同样,在横向模式下,我需要具有选项卡的文本颜色,白色(#FFFFFF)。 I'm using the Light.DarkActionBar theme and setting the text color via the style as shown below. 我正在使用Light.DarkActionBar主题,并通过样式设置文本颜色,如下所示。

In the /values folder / values文件夹中

<?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. 我决定使用资源修饰符修复此问题,并在values-land文件夹下创建了一个带有-land修饰符的新资源文件夹,该文件夹具有横向使用时的新标签文本样式,如下所示。

In the /values-land folder / values-land文件夹中

<?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). 但是...如果我返回Android主屏幕,将设备置​​于横向, 然后启动应用程序 ,则使用正确的资源样式(标签文本为白色)。 If I rotate it back to portrait, it stays white. 如果将其旋转回纵向,它将保持白色。 I expect it to go back to the darker color (#585858) 我希望它能恢复到较深的颜色(#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. 似乎Android或ActionBar正在忽略方向更改,而不是再次查找样式。 Anyone have any idea? 有人知道吗

It sounds like you have android:configChanges="keyboardHidden|orientation" (or something similar) in your manifest. 听起来您的android:configChanges="keyboardHidden|orientation"android:configChanges="keyboardHidden|orientation" (或类似名称)。 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. 这也将导致活动在旋转时重新加载,因此请确保您也妥善处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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