Skip to content Skip to sidebar Skip to footer

How Do I Inspect The Layout Of An Alert Dialog Using Layout Inspector?

I am trying to understand the spacing of elements in an AlertDialog. The AlertDialog is created using AlertDialog.Builder and contains a custom ListView (set via setView). When the

Solution 1:

I had the same issue. (I'm using Android Studio Arctic Fox 2020.3.1 patch 3)

Turned out the inspector by default filters out System-defined layers, and the dialog is one. There's this small button in the layout inspector, which looks like a filter.

Click it, disable the "Filter system defined layers" and another layer appears.

Before:

enter image description here

After:

enter image description here

Solution 2:

Using Android Studio Arctic Fox on Windows 10:

  1. Bring up the app with the dialog window showing in an emulator.
  2. Bring up the Layout Inspector View->Tools Window->Layout Inspector or you may have this in the lower right portion of the AS window

enter image description here

  1. You should see the Layout Inspector window pop up showing two DecorViews. (You may need to select the application.)

enter image description here

The top DecorView is the AlertDialog window. Click down through its hierarchy to see this:

enter image description here

From here you can see a visualization of the layout and the associated attributes:

enter image description here

In my experience, the Layout Inspector can be finicky at times. If the layout doesn't appear, try closing the Layout Inspector and restarting it.

Solution 3:

I wasn't able to get the alert dialog showing up in layout inspector, and had to use UI Automator Viewer

It's like Layout Inspector, but supports system and multi-app UIs, whereas Layout Inspector only supports single-app UIs. It feels like this UI is part of my app, but it's only showing up in UI Automator Viewer.

Post a Comment for "How Do I Inspect The Layout Of An Alert Dialog Using Layout Inspector?"