Different screens
Phones, tablets, cutouts and font scaling: writing a theme that survives a device you have never seen.
On this page
A theme laid out in fixed numbers on one phone is wrong on the next one. Every position and size is a formula, so the fix is usually one expression.
Measure against the screen, not the memory of one#
"y": "$screen_height - 110$" a dock 110dp from the bottom of any screen
"width": "$screen_width - 32$" a card with 16dp of margin either sidescreen_width and screen_height are in density-independent pixels, so they already account for the pixel density. What they do not account for is what the system draws over: use status_bar_height and nav_bar_height rather than guessing, since a device with gesture navigation reports 0 for the second one.
inset_left and inset_right are the cutout and rounded-corner insets, and matter mostly in landscape, and is_landscape tells you when you are there.
Grids should count, not assume#
A grid with four columns has 56dp icons in 200dp cells on a tablet. Derive the count:
"gridColumns": "$max(4, floor((screen_width - 16) / 96))$"Watch the aspect ratio of a cell#
A grid cell is as wide as the column and as tall as the row. When a theme fixes a dock's height in dp and derives its columns from the screen, a wide device gives square-ish cells on a phone and letterboxed ones on a tablet. Derive both from the same measurement, or fix the cell and let the count vary.
Respect the font setting#
font_scale is the system's text-size factor. A layout that ignores it either clips text for people who enlarged it or wastes space for people who did not:
"fontSize": "$16 * font_scale$"Check before you publish#
The store shows which of eight reference shapes a theme fits, by evaluating its formulas at each of those sizes and looking for elements that end up off-screen.
You do not have to guess what those shapes look like. The editor's preview device draws the theme at any of them, with the same list, sizes, bars and insets, so a shape the check flags can simply be looked at. Start with the small phone and the landscape phone: one is the narrowest, the other leaves 411dp of height for everything, and between them they find almost every layout bug in the first second.
Two settings there belong to this page as much as the size does: font_scale, which is the fastest way to see text clip, and the insets, which only matter in landscape and are therefore the ones nobody tests.
Documentation for launcher 0.1.0-alpha Android 12 and later last updated