How to Implement Dark Mode Theme in Android? - android

Android Q launched by Google, Dark Theme was released with it. Dark Mode applies to both the system UI and the apps running in it.
I want to implement this feature to application, any good suggestions ?
Help will be appreciated !

Make sure you import the latest version of the google material library
com.google.android.material:material:version.latest
Then you can set your apps theme to Theme.MaterialComponents.DayNight....
This will switch your UI to a dark theme variant when the user toggles it in their system
https://developer.android.com/guide/topics/ui/look-and-feel/darktheme

In order to support Dark theme, you must set your app's theme (usually found in res/values/styles.xml) to inherit from a DayNight theme:
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
for more information

Related

Android - System doesn't recognize my theme as dark mode

I have two themes. One is:
<style name="ThemeDay" parent="Theme.AppCompat.Light.NoActionBar">
Other one is:
<style name="ThemeNight" parent="Theme.AppCompat.DayNight.NoActionBar">
I apply themes in every activity like this before super.onCreate()
if(GenelUtil.getNightMode()){
setTheme(R.style.ThemeNight);
}else{
setTheme(R.style.ThemeDay);
}
Theme is applied. But system doesnt behave like selected theme.
For example when system is light mode and app is dark mode, Navigation bar is still white, dialogs are still white etc..
But when I open instagram and switch to dark mode, system also behave like its in dark mode.
What do I do wrong here? How can I fix this?
DayNight theme is picking automatically dark or light params/colors basing on system settings (by default) or set/forced by you (e.g. using AppCompatDelegate.setDefaultNightMode())
when you have light theme in your system and you will use DayNight theme for your app then still not overriden colors will be same as in "light" theme

How to disable automatic change of day night theme based on android system settings?

So far I have learnt from google, you have to use Theme.Appcompat.Daynight or Material Daynight theme to make your app support dark mode. And you need to use different styles.xml in values and values-night directories.
I am not willing to make my app support dark theme. But when I change android system theme (from notification panel) to dark, my app becomes dark.
I am using Theme.Appcompat.Light as base theme, did nothing for my app to support dark mode, still my app becomes dark. I am using cardview for the very first time, don't know if it may be the cause since I am very new in android programming.
Your little help will be much welcome. Please, check screenshots here:
System dark mode off
System dark mode on
You can use this in all application
class AppController: Application() {
override fun onCreate() {
super.onCreate()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
in android 10 ,android forse dark to app to pervent that ,
add below to your defult theme in style :
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
Add this line inside onCreate method of the MainActivity before calling setContentView:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

Tipsi-Stripe - How to Change Theme

I am using Tipsi-Stripe and NativeBase in my react-native, app, but I have not changed any theme variables (to my knowledge), but the components displayed from tipsi stripe seem be in some sort of "dark/night" theme.
Does anybody know where I should be looking to update these theme variables? I have looked at node_modules/native-base/src/theme/variables/ files, but they all appear to be nativebase defaults.
Screenshot:
NativeBase does not provide light or dark themes. It comes with commonColor, platform, material themes.
Though you can create light or dark themes on your own

Properly set SeekBar style for Holo and pre-Holo APIs

After setting SeekBar with Holo style, I got warning that it's not supported pre-Holo APIs.
If I leave it this way, will this crash the app or pull pre-Holo style anyway? It does not crash on the emulator and I don't have 2.3.3 device.
The reason for asking his is odd behaviour. I tried to manually set style for Holo and pre-Holo using res/values-v11/ directories and placing styles.xml in each and setting the style of SeekBar to style="#style/settings_seekbar" .
Style for API 11+ looked like this
<style name="settings_seekbar">
<item name="android:seekBarStyle">#android:style/Widget.Holo.SeekBar</item>
</style>
and style for APIs older than 11 looked like this
<style name="settings_seekbar">
<item name="android:seekBarStyle">#android:style/Widget.SeekBar</item>
</style>
So it looked like this would work. But on either device with Android 4.0+, I don't see Holo's theme, but the old thick-yellow theme.
If this is the proper way of settings styles (in case the first solution will crash a device), where did I make a mistake thus Holo theme never appeared on newer devices?
It seems we can safely use a theme from the upper SDK because I found no indicators that it will ever crash the app.
If the theme does not exist, Android will use the appropriate lower-level theme.
The error we can see on the image is just a warning that UI will not look the same in the SDKs which do not support this theme.

Android - apply theme from older API

I would like to deploy my app on APIs 8-17. However, for purely aesthetic reasons I would like to apply the default theme as it appears on api 8 as the theme for the app across all API levels.
For example, the older theme has an edittext that has an orangeish border around it, whereas the newer them uses a borderless blue line.
By limiting which APIs i deploy too I have been able to accomplish this but that isn't really a solution.
Does anyone know how this can be accomplished?
Thanks
Update
For whatever reason applying "Theme" as the theme did not force it to revert to the "Theme" theme, but instead left it as the default Holo. Using the answers below I simply called "Theme" as the parent in my custom theme (without altering any of its attributes) and set it as my application theme in the manifest. This solved it.
In your res/values directory, you can have a themes.xml file with:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="#android:Theme">
</style>
</resources>
Your app theme will now subclass from default Theme instead of Theme.Holo and you should be able to get older theme on newer android versions as well.
If you're using the default theme, it will be different between the API levels. However in the styles, you can create a custom Theme, modify an existing Theme or give a different Theme to each different API of your choice.

Categories

Resources