开发者

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

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 an开发者_开发知识库d 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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜