DTR
DTR

Reputation: 33

How to use the Android GreenMatter lib to change ColorAccent, ColorPrimary in Code?

Hi i want to use the GreenMatter (https://github.com/negusoft/GreenMatter) lib to change ColorAccent, ColorPrimary and others by code (Programmatically override the colors at runtime).

I have setup the lib in my Android Project with https://github.com/negusoft/GreenMatter/wiki/Basic-GreenMatter-setup. But by analyzing the Greenmatter code i can't find out how i could use for example a integer (color) to change ColorAccent or ColorPirmary in my Android Project.

Upvotes: 0

Views: 420

Answers (1)

Jeff Lockhart
Jeff Lockhart

Reputation: 5611

After following the steps in the setup guide, you should have an Activity that extends MatActivity. In your Activity you can change the default colors of your theme by overriding overridePalette() and setting the colors as you'd like in the MatPalette object parameter and returning it.

public class MyActivity extends MatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public MatPalette overridePalette(MatPalette palette) {

        palette.setColorPrimary(Color.GRAY);
        palette.setColorPrimaryDark(Color.DKGRAY);
        palette.setColorAccent(Color.LTGRAY);
        return palette;
    }
}

Upvotes: 1

Related Questions