Android ExpandableListView not changing to light text in night mode

187 Views Asked by At

I am creating an ExpandableListView and its adapter (ExpandableListAdapter, using a SimpleExpandableListAdapter) by doing something like this. It works fine in light mode, but the text remains black in dark mode / night mode, while the rest of my application is styled correctly:

    ExpandableListAdapter adapter = new SimpleExpandableListAdapter(
                activity.getApplicationContext(), 
                groupData, groupLayout, groupFrom, groupTo,
                childData, childLayout, childFrom, childTo);
    ExpandableListView expandableListView = view.findViewById(R.id.my_expandable_list_view);
    expandableListView.setAdapter(adapter);
1

There are 1 best solutions below

2
axby On BEST ANSWER

Instead of passing in activity.getApplicationContext() as the context argument when creating the SimpleExpandableListAdapter, pass in the activity directly. The theme on the application context appears to be wrong:

    ExpandableListAdapter adapter = new SimpleExpandableListAdapter(
                activity /* instead of activity.getApplicationContext() */, 
                groupData, groupLayout, groupFrom, groupTo,
                childData, childLayout, childFrom, childTo);

Though others recommend using a RecyclerView instead of a ListView/ExpandableListView.

Credit to this reddit post by u/TheCrazyRed.