Enable layout debugging in Android using ADB

Debugging the layout is one of the important task for any Android developer. Have you have ever tried enabling Show layout bounds during debugging. These are the Steps that I usually take during debugging the layout.

  1. Some view doesn’t look right (The bug)
  2. Go to settings
  3. Then go to systems
  4. Then developer options
  5. Then enable Show layout bounds
  6. Return to the app (And most probably forget which view I was going to debug 😂).

This is real pain when you have to constantly enable and disable this option for debugging. But fear not my friend ADB to the rescue. We can use adb shell commands to enable this option from the command line.

adb shell setprop debug.layout true// poke the system properties to activate the changes
adb shell service call activity 1599295570

You might be wondering where the 1599295570 number came from. This is called SYSPROPS_TRANSACTION and used by settings app to refresh the setting.

Typing these two commands every time you want to enable or disable is quite inconvenient. So I made a simple bash script to handle this.

#!/bin/bashflag=$1
value=$2
shift
shift
adb "$@" shell setprop debug.$flag $value
adb "$@" shell service call activity 1599295570

Save this script in whatever location you like (I save this in /usr/local/bin) with some name like debug. Then use chmod +x command to make this executable. Now whenever you want to enable this option just type debug layout true and to disable type debug layout false. You can also further optimize the command by using alias in bash. To handle multiple options I have used shift commands in the script. So, let’s say you have two devices connected and run this command then the output will be

error: more than one device/emulator

To fix this you need to pass the device serial number which you can get from command adb devices . Let’s say the serial number is emulator-5554 then you can use the above command like this debug layout true -s emulator-5554 .

Again like I said you can use alias to make this a shortcut. You can look here to see different debug properties that you can configure like force_rtl . You can also use this app that provides various debug options if you don’t like to work with terminal.

That’s it for this story. If you have any questions or suggestions let me know in the comments below.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store