Floss
Floss

Reputation: 637

Android AppCompat Dark Theme Settings Checkbox

I have upgraded to v21 on the AppCompat library in the Support Library. When using the dark theme (@style/Theme.AppCompat), the checkboxes in the SettingsActivity are black so you can't even see them.

This was before the update:

enter image description here

This is after the update:

enter image description here

The checkboxes everywhere else in the app are fine. How do I fix the ones in the SettingsActivity?

Upvotes: 4

Views: 2178

Answers (3)

gordonwd
gordonwd

Reputation: 4587

I solved this problem by using the solution on this page to create a compatible PreferenceFragment class by copying the code into my project. I then replaced my former PreferenceActivity with a class inheriting from ActionBarActivity and instantiate a Fragment class derived from the new PreferenceCompatFragment class. This now work well to display my preferences with an Action Bar of the expected color as well as checkboxes that are properly accented. Here is the code for my new settings activity:

public class SettingsFragActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(R.id.content);
    setContentView(frame);
    this.getSupportFragmentManager().beginTransaction()
            .replace(R.id.content, new SettingsFragment (), null).commit();
    }


public static class SettingsFragment extends PreferenceCompatFragment {
    @Override
    public void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        addPreferencesFromResource(R.xml.prefs);
    }
}

}

Note that the addPreferencesFromResource belongs to the custom PreferenceFragment class.

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1006859

Make sure that your activity is inheriting from ActionBarActivity. Inheriting from Activity was giving me your effects; inheriting from ActionBarActivity fixed the problem. You can see the results in this sample project.

Upvotes: 2

Robert Estivill
Robert Estivill

Reputation: 12477

My guess is that's because the support library is not emulating the Holo theme anymore.

Have you try defining the colorAceent your theme ?

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">

   ...

    <!-- colorAccent is used as the default value for colorControlActivated,
     which is used to tint widgets -->
    <item name=”colorAccent”>@color/accent</item>

   ...

</style>

Reference:

http://android-developers.blogspot.com.ar/2014/10/appcompat-v21-material-design-for-pre.html

Upvotes: 0

Related Questions