Previously, the Holo Light theme was applied throughout my entire App. That is however no longer the case it may seem.
Although the Action Bar, background and whatnot are correct, other parts are not. Specifically, the default text color is now very light grey, almost white, as well as some CheckBoxes appears to be using an older theme.
The following images demonstrates the checkbox issue (don't mind the icon to the left or the background color):
I haven't had this issue in the 2 months before today, that I've been developing this App, so I am guessing I must have done something to cause this weird behaviour. I've tried retracing my steps, but with no success.
The views containing these checkboxes are displayed in a ListView, but when I display checkboxes other places in the App, outside of this ListView, they appear as expected.
I would like to point out that the checkbox is not the only issue, the default text color also got messed up, everywhere in the App.
My test device is a Samsung Galaxy S3 Mini running Android 4.1.2.
build.gradle
...
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 17
}
...
res/layout/___.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="@dimen/spacing"
android:layout_marginBottom="@dimen/spacing"
android:layout_marginLeft="@dimen/spacing"
android:layout_marginRight="@dimen/spacing"
android:contentDescription="@string/cd_icon" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_marginRight="@dimen/spacing"
android:layout_marginTop="@dimen/spacing"
android:layout_marginBottom="@dimen/spacing">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="@dimen/text_size_medium"
android:textColor="@android:color/primary_text_light"/>
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_small"
android:textColor="@android:color/secondary_text_light"/>
</LinearLayout>
<CheckBox
android:id="@+id/active"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:checked="true"
android:layout_marginRight="8dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"/>
</LinearLayout>
AndroidManifest.xml
...
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
...
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
</resources>
Solution
I narrowed down the issue to only ListViews and did some more searching on that. It turns out that I was using the wrong context in my list adapters. The solution was quite simple: Use the activity context instead of the application context in adapters.
Before
public DelegatedAdapter(Context context) {
mContext = context.getApplicationContext();
mInflater = LayoutInflater.from(mContext);
}
After - Custom ListView in Fragment not adhering to parent theme
public DelegatedAdapter(Context context) {
mContext = context;
mInflater = LayoutInflater.from(mContext);
}