TransWikia.com

Get the size of the navigation bar using ADB

Android Enthusiasts Asked by Spyder on October 29, 2021

I want to know what is the size of the navigation bar in pixel using ADB.

Using adb shell wm size gives the complete screen size instead of only the navigation bar.

Is there any way to get it?

2 Answers

on my device(OnePlus 3 running Android 9), it should change NavigationBar to StatusBar

➜  adb shell dumpsys window windows| sed -n '/Window .*StatusBar.*:/,/Window .*:/p'| grep 'Requested'

get this

Requested w=1080 h=63 mLayoutSeq=3640

Answered by Frank Fan on October 29, 2021

Enter this one-liner:

adb shell dumpsys window windows| sed -n '/Window .*NavigationBar.*:/,/Window .*:/p'| grep 'Requested'

Alternatively, if you don't have Linux/Mac, try this:

adb shell
dumpsys window windows | toybox sed -n '/Window .*NavigationBar.*:/,/Window .*:/p'| grep 'Requested'

What's happening in that one liner is this:

  1. we use dumpsys to output all the details of all the windows displayed on the screen (irrespective of the screen on or off)

  2. we filter the content using sed to show only those lines which have information about Navigation Bar

  3. we grep the information we need.

    You can alternatively try grepping for grep mSystemDecorRect. I don't know which one is more reliable in all circumstances.

Expected output example:

Requested w=1080 h=126 mLayoutSeq=10835

# if 'mSystemDecorRect' was grepped, then:

mSystemDecorRect=[0,0][1080,126] mLastClipRect=[0,0][1080,126]

w: width, h: height, of your navigation bar respectively.

Note: for some reason if the one-liner fails to work or gives unexpected output, filter it like this. Get the dump using that first dumpsys command, then find the entry for your NavigationBar, and within that, look for the size.

Tested on OnePlus 6 running Android 10.

Credits: Fiximan of Unix & Linux for sed command.

Answered by Firelord on October 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP