I have a settings activity
public class SettingsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
And a fragment:
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.settings, rootKey);
}
}
activity_settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/activitySettings_updateFrequencyValueText"
android:layout_width="50dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="@id/view_settings_fragment"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
android:ellipsize="marquee"
android:gravity="center"
android:textSize="15sp"
android:paddingStart="10dp"
android:paddingLeft="10dp"
>
</TextView>
<fragment
android:name="com.myapp.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_settings_fragment"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="bus_update_frequency"
android:title="@string/bus_update_frequency"
android:summary="@string/bus_update_frequency_desc"
android:entries="@array/bus_update_frequency_entries"
android:entryValues="@array/bus_update_frequency_values"
android:defaultValue="10 seconds"
/>
</PreferenceScreen>
res/values/arrays.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="bus_update_frequency_entries">
<item>10 seconds</item>
<item>20 seconds</item>
<item>30 seconds</item>
<item>40 seconds</item>
<item>50 seconds</item>
<item>60 seconds</item>
</string-array>
<string-array name="bus_update_frequency_values">
<item>10</item>
<item>20</item>
<item>30</item>
<item>40</item>
<item>50</item>
<item>60</item>
</string-array>
</resources>
Everything works great the settings page looks like so:
But when you open the ListPreference the text is in white for some reason. It looks like this, you can see that the text is in there when you highlight it.
I have not figured out how to change it to black since the ListPreference has no textColor attribute. Any ideas?
EDIT:
I think what is causing this is my alert dialogs are the maroon color in the action bar, with white text. So how do I change either the background color of the ListPreference to that color or change the text color through themes?
EDIT2:
Nevermind, changing the color of the alert text did not change the color of the ListPreference text.
I have no idea what was causing this issue, but I did eventually solve it
To solve this I had to create my own custom theme:
<style name="PreferencesTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorPrimary">@color/primaryBlack</item>
<item name="android:textColorSecondary">@color/colorPrimary</item>
<item name="android:textColorTertiary">@color/primaryBlack</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimary</item>
<item name="textColorAlertDialogListItem">@color/primaryBlack</item>
</style>
<style name="PreferencesTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="PreferencesTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
and then set the theme in the on create method of the activity:
public class SettingsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.PreferencesTheme);
super.onCreate(savedInstanceState);
The specific item that made the dialog text black was this one:
<item name="textColorAlertDialogListItem">@color/primaryBlack</item>