Question

Background

I'm adding a theme chooser of "Holo" and "Holo Light" (and maybe the dark action bar too) for my app "App Manager". For now I first try them out, via XML files.

The problem

I'm using the support library by Google and try out the themes, yet no matter what attributes and themes I use, the textViews' color on my listView have the wrong color.

The listView contains 2 TextViews that are defined as such:

<TextView
    android:id="@+id/appLabelTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/isSystemAppImageView"
    android:layout_toRightOf="@+id/appIconImageView"
    android:ellipsize="marquee"
    android:text="label"
    android:textAppearance="?android:attr/textAppearanceLarge"
    tools:ignore="HardcodedText" />

<TextView
    android:id="@+id/appDescriptionTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/appLabelTextView"
    android:layout_below="@+id/appLabelTextView"
    android:layout_toLeftOf="@+id/isSystemAppImageView"
    android:ellipsize="marquee"
    android:text="description"
    android:textAppearance="?android:attr/textAppearanceSmall"
    tools:ignore="HardcodedText" />

Theme.AppCompat.Light and Theme.AppCompat:

enter image description here enter image description here

Same happens when I do it all programmatically, and when I use ActionBarSherlock library.

Here's the themes configurations I use (tried ActionBarSherlock this time, but the same occurs for the normal support library) :

<style name="BaseTheme" parent="@style/Theme.Sherlock.Light"></style>

<style name="AppTheme" parent="@style/BaseTheme">
    <item name="android:listSeparatorTextViewStyle">@style/PreferenceListHeader</item>
    <item name="android:windowBackground">@color/normal_window_background</item>
</style>

and the manifest:

<application
    android:name="com.lb.app_manager.utils.App"
    android:allowBackup="true"
    android:description="@string/app_description"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

The activity I've shown here doesn't have any code or XML that sets the theme to be different from what is written above.

What I've tried

I've tried to check out the samples and saw no apparent difference between the XMLs and code. They work just fine...

Also, for some reason, the preferences activities are shown just fine.

Same issue exists on ActionBarShelock library.

The question

How could it be ? what should be done to fix it?

Was it helpful?

Solution

I've found the cause to this problem.

It wasn't related to any XML or setting styles .

It was because of the LayourInflater of the adapter. I've created it via the application context instead of the one of the activity.

It also explains why my tests on sample projects worked fine, as I've checked the wrong stuff...

OTHER TIPS

In Holo light theme and other Light themes we need to set Text color the only it will work..

  <TextView
  android:id="@+id/appLabelTextView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentTop="true"
  android:layout_toLeftOf="@+id/isSystemAppImageView"
  android:layout_toRightOf="@+id/appIconImageView"
  android:ellipsize="marquee"
  android:textcolor="#000"
  android:text="label"
  android:textAppearance="?android:attr/textAppearanceLarge"
  android:textStyle="bold"
  tools:ignore="HardcodedText" />

  <TextView
  android:id="@+id/appDescriptionTextView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/appLabelTextView"
  android:layout_below="@+id/appLabelTextView"
  android:layout_toLeftOf="@+id/isSystemAppImageView"
  android:ellipsize="marquee"
  android:textcolor="#000"
  android:text="description"
  android:textAppearance="?android:attr/textAppearanceSmall"
  tools:ignore="HardcodedText" />

Hope this will work.. Try this and let me know the result.

I tried the sample you provided with Theme.AppCompat and Theme.AppCompat.Light, and they both work correctly as expected, on both API level 10 and 18. Since you didn't provide full code, only snippets, it must be the case that there are additional bits of XML or code in your application somewhere that cause the problem.

A couple of things for you to check:

  • Remove these entries from your AppTheme definition to make sure they are not interfering and causing the problem:

    <item name="android:listSeparatorTextViewStyle">@style/PreferenceListHeader</item>
    <item name="android:windowBackground">@color/normal_window_background</item>
    
  • You may have different style definitions for different API levels. Check the contents of res/values-v11/styles.xml, res/values-v14/styles.xml etc. to make sure they are not interfering

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top