Implementing Dark Mode in Android App

With the launch of android 10, Google announced the much-awaited Dark Mode. The developers can use the provided API and allow the user to activate dark mode in their app.

In this blog, we will create an app that can activate dark mode on a single click. Let us begin by creating an app in Android Studio. You can read more about dark mode here.

We need to create a dark and light style, we will use this in our app.

Now, create this new resource file:

We will need to add a circular image in our layout, we will use a circular imageview library given here:

Now let us create our main layout;

Now our app looks like this:

Our layout and style part is done, now we have to change the theme on button click. But remember, we have to provide a default light theme to the app. The user can change the theme on button click.

Here is MainActivity.java file:

With the above code, by default, we have set the light theme to our app. We have to set listeners to our buttons.

And voila! We are done!

You can find the project on Github here. Do clap if you find this useful.

Founder at Inside Android | Youtuber | App Developer