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

点点圈 提交于 2020-01-12 01:16:21

问题


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


回答1:


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




回答2:


You don't need to start the settings app. Just exit your app, set the property, and start your app.

adb shell am force-stop com.company.appname ; adb shell setprop debug.layout true ; adb shell monkey -p com.company.appname -c android.intent.category.LAUNCHER 1



回答3:


I found a DevelopQuickSetting tool can easily make this. https://github.com/kyze8439690/DevelopQuickSetting

and the core code translate to adb shel is:

adb shell setprop debug.layout true
adb shell service check SurfaceFlinger



回答4:


This tool works fine. You need to install groovy before launch this program.

https://github.com/dhelleberg/android-scripts



来源:https://stackoverflow.com/questions/23799848/how-to-easily-show-layout-bounds-for-android-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!