How do I change the text colour of the letter popup when using a ListView with Fast Scroll enabled?

1.6k Views Asked by At

I'm having a slight issue with the Light theme and a fast scrolling ListView. As you can see in the image below, when using the Light theme the pop up for the current letter when dragging the scroll bar contains black text on a dark gray background, making it very hard to read and just look ugly.

If I override android:textColorPrimary in a Theme it changes color, but so do all the items in the ListView, as well as other UI elements elsewhere in the app, so it's not a viable solution.

I'm using GreenDroid and it's associated classes, but looking through the source code, it seems to just use a standard ListView so is unlikely to be the issue.

I also found this question, which makes it seem likely that it's not a GreenDroid issue, but unfortunately the solution given by the author in a comment doesn't explain in enough detail how to fix it.

Any ideas as to how to solve this?

Thanks, Daniel

Example of popup issue

2

There are 2 best solutions below

2
On

i've found an answer here:

https://gist.github.com/DHuckaby/d6b1d9c8e7f9d70c39de

public class CustomListView extends ListView {

    public CustomListView(Context context, AttributeSet attrs) {
        super(new ContextThemeWrapper(context, R.style.CustomListView), attrs);
    }
}

styles.xml

<resources>
    <style name="CustomListView" parent="@style/GlobalTheme">
        <item name="android:textColorPrimary">?android:textColorPrimaryInverse</item>
    </style>
</resources>
0
On

The easiest way to do this is to define a special Theme that you apply only to the ListActivity, like this.

<style name="Theme.MyApp" parent="@style/Theme.GreenDroid.Light.NoTitleBar">
    ...
</style>

<style name="Theme.MyApp.TweakedItems" parent="@style/Theme.MyApp">
    ...
    <!-- Default color for Android Dark Theme -->
    <item name="android:textColorPrimary">@android:color/primary_text_dark</item>
</style>

Then you can modify any ItemView from GreenDroid to apply a different color.

<?xml version="1.0" encoding="utf-8"?>
<greendroid.widget.itemview.TextItemView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="?attr/gdTextItemViewStyle"
    android:id="@+id/gd_text"
    android:layout_height="?attr/gdItemViewPreferredHeight"
    android:minHeight="?attr/gdItemViewPreferredHeight"
    android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft"

    android:singleLine="true"
    android:ellipsize="end"

    android:gravity="center_vertical"
    android:textColor="#000000" />

Starting from API Level 11 you can change the color using fastScrollTextColor