Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to easily "Show Layout bounds" for Android debugging?

Tags:

I want to watch the layout of App without boring tap and tap.


I tried adb shell setprop debug.layout true but didn't work unless reboot or open setting.
This may caused by setting haven't update.

I tried to writing a little App with code SystemProperties.set("debug.layout", "true") , no use too.
Maybe the app's authority…


Sorry for my poor English and appreciation for help :p

like image 251
likaci Avatar asked May 22 '14 06:05

likaci


People also ask

What is Show layout bounds in Android?

On Android, we have an option called Show layout bounds , which allows us to see bounding areas of your views displayed in vibrant blue and purple.


1 Answers

This works for me:

adb shell setprop debug.layout true
adb shell service call activity 1599295570

After we have enabled Show layout bounds using adb shell setprop debug.layout true, we have to poke the SystemProperties to see the changes as Show layout bounds QS Tiles does:

@Override
public void onClick() {
    setIsEnabled(getQsTile().getState() == Tile.STATE_INACTIVE);
    new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic
    refresh();
}

Here's the original method from AOSP source:

public static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        String[] services = ServiceManager.listServices();
        for (String service : services) {
            IBinder obj = ServiceManager.checkService(service);
            if (obj != null) {
                Parcel data = Parcel.obtain();
                try {
                    obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
                } catch (RemoteException e) {
                } catch (Exception e) {
                    Log.i(TAG, "Someone wrote a bad service '" + service
                            + "' that doesn't like to be poked: " + e);
                }
                data.recycle();
            }
        }
        return null;
    }
}

The number 1599295570 is called SYSPROPS_TRANSACTION

Reference: https://github.com/dhelleberg/android-scripts/blob/master/src/devtools.groovy

UPDATED: I created this app to add many developer toggle to the quick settings for Android 7.0+

like image 59
Simon Pham Avatar answered Sep 28 '22 03:09

Simon Pham