简体   繁体   English

Android如何在方向更改时动态更改动作栏标签文本颜色

[英]Android how to dynamically change actionbar tabs text color on orientation change

I'm using a FragmentActivity implementing ActionBar.TabListener. 我正在使用实现ActionBar.TabListener的FragmentActivity。

I have themed my top/title bar to have a dark background, and a white font. 我的顶部/标题栏以深色背景和白色字体为主题。

My three tabs, stacked below, have a light background and black font. 我的三个标签堆叠在下面,具有浅色背景和黑色字体。 This looks good in portrait, but for devices with more horizontal pixels, such as tablets, or landscape phones, the tab bar is absorbed into the main title bar. 纵向显示效果不错,但是对于水平像素更多的设备(例如平板电脑或横向手机),选项卡栏会被吸收到主标题栏中。 This behavior itself is fine, but the tab font is black and I need to change it to white for this specific scenario. 此行为本身很好,但是选项卡字体为黑色,对于这种特定情况,我需要将其更改为白色。

Is this supported? 支持吗?

I have figured out how to change the bottom highlight color and the tab background color, thanks to Is it possible to change actionbar tab indicator programmatically but I haven't been able to programatically change the font color yet. 我已经弄清楚了如何更改底部突出显示颜色和选项卡背景颜色,这要归功于“ 是否可以通过编程方式更改操作栏选项卡指示器”,但是我还无法通过编程方式更改字体颜色。

I have tried creating a Spannable object, setting the color of that, then assigning that via myTab.setText(), but the theme seems to be overriding this color, although the text characters change is recognized. 我尝试创建一个Spannable对象,设置该对象的颜色,然后通过myTab.setText()进行分配,但是尽管可以识别文本字符,但主题似乎覆盖了该颜色。

Found a workable solution myself: 我自己找到了一个可行的解决方案:

Using "values-land" and dpi-based descriptors I can use an alternate style for that specific instance (eg, landscape, or high DPI devices like tablets). 使用“ values-land”和基于dpi的描述符,我可以为该特定实例使用替代样式(例如,风景或平板电脑等高DPI设备)。

Create a 'values-land' folder and a styles.xml file inside of that automatically uses those styles for landscape views. 创建一个“ values-land”文件夹,并在其中创建一个styles.xml文件,该文件会自动将这些样式用于景观视图。

More info on how to do this: http://developer.android.com/guide/topics/resources/providing-resources.html 有关如何执行此操作的更多信息: http : //developer.android.com/guide/topics/resources/providing-resources.html

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

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