Jitin
Jitin

Reputation: 344

How Do I extend Android Material Dark Theme

I know I might be making more than enough mistakes here. But do lemme know. I've tried going through MaterialIO documentation the best way I can, and it all looks so spun up and complicated with a dozen links in each page redirecting me to another minor component. That's when I decided to TRY it.

<application ...
        android:theme="@style/Theme.MaterialComponents.DayNight" >
</application>
<?xml version="1.0" encoding="utf-8"?>
<resources>
        <style name="AppCompat.." parent="Theme.MaterialComponents.DayNight">
                <item name="android:colorBackground">@color/JDBG</item>
                <item name="colorSurface">@color/JDSurface</item>
                <item name="colorPrimary">@color/JDPrimary</item>
                <item name="android:colorSecondary">@color/JDSecondary</item>
                <item name="android:OnBackground">@color/JDOnBackground</item>
                <item name="android:OnSurface">@color/JDOnSurface</item>
                <item name="OnPrimary">@color/JDOnPrimary</item>
                <item name="OnSecondary">@color/JDOnSecondary</item>
        </style>
</resources>

I do not want to toil at nothing with very abstract documentation that leads me on ten directions at every point. Hence the question . . . Is there anything wrong I've done ? What do I do next ?

Upvotes: 0

Views: 653

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363935

Just define your theme in a resources file.
For example res/values/styles.xml:

<style name="MyTheme" parent="Theme.MaterialComponents.DayNight">
    <item name="colorPrimary">@color/....</item>
    <item name="colorSecondary">@color/....</item>
    <item name="colorOnPrimary">@color/....</item>
    <item name="colorOnSecondary">@color/....</item>
    .....
</style>

Define the colors in res/values/colors.xml and res/values-night/colors.xml.

Then apply the theme in the Manifest:

<application ...
        android:theme="@style/MyTheme" >

Check also the official guide.

Upvotes: 1

Related Questions