Android AppCompat Dark Theme Settings Checkbox

I have updated to v21 on the AppCompat library in the Support Library. When using a dark theme (@ style / Theme.AppCompat) the checkboxes in 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

Checkboxes everywhere in the app are great. How can I fix them in the setup?

+3


source to share


3 answers


I solved this issue by using the solution this page to create a compatible PreferenceFragment class by copying the code into my project. Then I replaced the old PreferenceActivity with a class that inherits ActionBarActivity, and instantiate the Fragment class derived from the new PreferenceCompatFragment. This now works well to display my settings with the action bar in the expected color, as well as checkboxes that are correctly accented. Here is the code for my new settings:

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 addPreferencesFromResource belongs to the custom PreferenceFragment class.

+2


source


Make sure your activity inherits from ActionBarActivity

. Inheritance from has Activity

given me your consequences; inheriting from ActionBarActivity

fixes the problem. You can see the results in this sample project .



+2


source


I am guessing because the support library no longer emulates the Holo theme.

Try to define 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>

      

Link:

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

0


source







All Articles