Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to enable the "Show layout bounds" developer option programmatically?

For example, I can manipulate ADB debugging using:

Settings.Secure.putInt(getActivity().getContentResolver(),Settings.Secure.ADB_ENABLED, 1);

Is it possible to enable the "Show layout bounds" option in a similar manner? I haven't been able to find any documentation on it.

like image 697
ter0 Avatar asked Sep 17 '13 11:09

ter0


People also ask

How do I enable developer options programmatically?

Enable developer options and USB debugging On Android 4.1 and lower, the Developer options screen is available by default. On Android 4.2 and higher, you must enable this screen. To enable developer options, tap the Build Number option 7 times.

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.


2 Answers

No, AFAIK it is not available. One thing I have done, however, is tint all my views to see where they are bound and where they overlap, etc. You can use this code, which uses the droidQuery library to select all views to iterate over:

public static void debugLayout(View layout)
{
    $.with(layout).selectAll().each(new Function() {
        @Override
        public void invoke($ d, Object... args) {
            View v = d.view(0);
            Drawable drawable = v.getBackground();
            if (drawable != null)
                drawable.setColorFilter(0xAAFF0000, PorterDuff.Mode.MULTIPLY);
            else
                drawable = new ColorDrawable(0xAAFF0000);
            try {
                //API 16+
                v.setBackground(drawable);
            }
            catch (Throwable t) {
                v.setBackgroundDrawable(drawable);
            }
        }
    });
}
like image 81
Phil Avatar answered Oct 13 '22 01:10

Phil


There may be something you can do to simulate what the Settings code actually does:
https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/DevelopmentSettings.java#L942

private void writeDebugLayoutOptions() {
    SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
        mDebugLayout.isChecked() ? "true" : "false");
    pokeSystemProperties();
}
like image 40
swooby Avatar answered Oct 13 '22 00:10

swooby