How to get the blue style text in 2.1 Contacts or Preferences

限于喜欢 提交于 2020-01-01 20:49:28

问题


Running Android 2.1, preferences and other dialogs have white/blue text. Looking at theme values I see things like textColorPrimary and textColorSecondary. If I reference those colors in my layout xml, with something like:

  android:textColor="?android:attr/textColorSecondary" 

I just see white text (I have tried textColorPrimary, textColorTertiary and textColorHint also).

I do not have any theme values stated in my manifest file. I am presuming this means I am using the system default theme.

All that said, am I barking up the wrong tree with textColor* references?


回答1:


all the textColor* attributes point to color selectors. If you want to change the color for your theme you need to perform the following steps:

1) Create a color selector, create a file named (for example) primary_color.xml and put it under res\color folder

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@android:color/bright_foreground_light_disabled"/>
    <item android:state_window_focused="false" android:color="@android:color/bright_foreground_light"/>
    <item android:state_pressed="true" android:color="@android:color/bright_foreground_light"/>
    <item android:state_selected="true" android:color="@android:color/bright_foreground_light"/>
    <item android:color="@android:color/bright_foreground_light"/> <!-- not selected -->

2) In your styles.xml file, create a theme for your activity that references your newly created color selector:

<style name="ActivityStyle" parent="android:Theme">
        <item name="android:textColorPrimary">@color/primary_color</item>
        <!-- Add more styles here as necessary -->
</style>

3) In your AndroidManifest.xml, apply the new theme to any activity you want:

<activity android:name=".activities.MedicationsActivity"
       android:theme="@style/ActivityStyle">
 </activity>


来源:https://stackoverflow.com/questions/4440967/how-to-get-the-blue-style-text-in-2-1-contacts-or-preferences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!