navasmdc / MaterialDesignLibrary

This is a library with components of Android L to you use in android 2.2
Apache License 2.0
8.99k stars 2.22k forks source link

Do not hardcode colors #91

Open itadventurer opened 9 years ago

itadventurer commented 9 years ago

Thank you for all of your great work!

Accoding to http://www.google.co.uk/design/spec/components/buttons.html:

Buttons should be designed in accordance with your app’s color theme.

You should use ?android:attr/colorAccent as the main color instead of the hard coded blue. (According to https://developer.android.com/training/material/theme.html)

In Mirakel we are using now a ThemeManager to obtain the colors. Maybe you could use a similar approach too:

    public static int getAccentThemeColor() {
        return getColor(R.attr.colorAccent);
    }

    public static int getColor(int attrId) {
        // The attributes you want retrieved
        final int[] attrs = {attrId};

        // Parse MyCustomStyle, using Context.obtainStyledAttributes()
        final TypedArray ta = context.obtainStyledAttributes(themeResId, attrs);

        // Fetching the colors defined in your style
        final int color = ta.getColor(0, Color.BLACK);

        // OH, and don't forget to recycle the TypedArray
        ta.recycle();
        return color;
    }
muriloandrade commented 9 years ago

+1

vipulyaara commented 9 years ago

+1

huangcd commented 9 years ago

+1

voed commented 9 years ago

:heavy_plus_sign: