How to easily “Show Layout bounds” for Android debugging?

后端 未结 5 1852
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 21:31

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 re

5条回答
  •  孤独总比滥情好
    2021-02-01 22:16

    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 {
        @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+

提交回复
热议问题