Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwitchPreference default color

Tags:

java

android

xml

the application I am working on I have set the primary/dark/accent colors to the colors I desire and they appear in the correct locations (as expected). I have a preference activity that I am using though, and I was hoping that the color of the preferenceswitch's that I am using would render in the accent color. Instead they are rendering in the material teal color. I was wondering is this default behavior with Lollipop, like in Kitkat it was the blue? I don't even reference the color which is #009688 anywhere in my code or my colors.xml / styles.xml.

colors.xml

<resources>
    <color name="primary">#00BCD4</color>
    <color name="primary_dark">#0097A7</color>
    <color name="accent">#FFD740</color>
</resources>

styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:colorAccent">@color/accent</item>
    </style>
</resources>

Any Ideas? I'll provide any more info. I saw some stuff on here about creating custom stuff, but is that really necessary?

preferenceActivity.java

public class PreferenceActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PrefFrag prefFragment = new PrefFrag();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(android.R.id.content, prefFragment);
        fragmentTransaction.commit();
    }
}
like image 625
erp Avatar asked Mar 16 '23 20:03

erp


1 Answers

When you use AppCompat, you should use the non-prefixed versions of each attribute - this ensures that they are available on all API levels (unlike the android: ones, which only work on API21+ for example):

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>
like image 172
ianhanniballake Avatar answered Mar 25 '23 06:03

ianhanniballake