Color Scheme
Setting a dark or light style for your app
Last updated
Setting a dark or light style for your app
Last updated
elementary OS ships with two styles for app widgets: a dark style and a light style. By default, your app will use the light style, but by using Gtk.Settings
and Granite.Settings
you can choose to always use a dark style or to follow the user's preference.
Some apps, like photo or video editors, benefit from reducing the contrast between their content and the app's UI by always choosing to be displayed using a dark style. You can set the dark style for your app by using Gtk.Settings
and setting the property gtk_application_prefer_dark_theme
. In your Application class, add the following lines to your activate
function:
Here, we get the default Gtk.Settings
object and then we set this property to instruct GTK to use the dark style. Build your app and run it and notice that it now uses a dark style instead of a light style.
Many apps will be usable in either a light or dark style. In this case, apps should respect the user's style preference and adapt when it is changed.
First, make sure you've included Granite in the build dependencies declared in your meson.build file:
Now, you can read and respond to the user's style preference with Granite.Settings
and then use Gtk.Settings
to set it in your app's activate
function.