don
don

Reputation: 1607

Is there a quick way to toggle dark mode in the Android emulator?

I'm mainly using the Android emulator for development. Is there a quick way (ideally a keyboard shortcut) to switch between dark mode and light mode for testing the dark/light themes?

Upvotes: 11

Views: 4102

Answers (3)

Eerko
Eerko

Reputation: 136

pavelperc's answer doesn't work if you have multiple devices running. You can adjust the script to toggle dark mode for all running devices as follows (based on this answer):

alias adb="/Users/YOUR_USERNAME/Library/Android/sdk/platform-tools/adb"

for device in `adb devices | awk '{print $1}'`; do
  if [ ! "$device" = "" ] && [ ! "$device" = "List" ]
  then
    adb -s $device $@
    if [[ $(adb -s $device shell "cmd uimode night") == "Night mode: yes" ]]; then
      adb -s $device shell "cmd uimode night no"
    else
      adb -s $device shell "cmd uimode night yes"
    fi
  fi
done

Upvotes: 0

pavelperc
pavelperc

Reputation: 399

If you use MacOS, you can automate this action with a shortcut:

  1. Open Shortcuts.app
  2. Find action "Run shell script"
  3. Insert this script:
alias adb="/Users/YOUR_USERNAME/Library/Android/sdk/platform-tools/adb"
if [[ $(adb shell "cmd uimode night") == "Night mode: yes" ]]; then
  adb shell "cmd uimode night no"
else
  adb shell "cmd uimode night yes"
fi

  1. Select "Shortcut details" tab on the top right ("i" icon), click Add keyboard shortcut and add your shortcut.

Here is an example:

shortcuts example

Works perfectly!

shortcut gif

Upvotes: 15

australis
australis

Reputation: 481

Just to bring more visibility to the comment above with a great solution:

You should be able to add the dark mode tile in the [swipe down] notification shade, as you do with an actual device.

Obviously it will change slightly depending on the phone you are emulating but here is a demo for anyone not used to Android devices

dark mode in notification shade demo

Upvotes: 10

Related Questions