What do you mean by "via Android Studio" - are you talking about adding code and a UI for doing this in an app of yours? If so, I assume that adding a UI is not an issue (it would just be a checkbox or whatever that triggers switching the mode when touched).
At least as important as doing this manually is hooking into the system-wide setting. See
https://developer.android.com/guide/topics/ui/look-and-feel/darktheme for all about that.
That page also explains the API calls you can use to set the mode programmatically in your app, if you don't just want to follow the system setting.