Blocks are composed of three components:
- Block definition object: Defines the look and behavior of a block, including the text, color, fields, and connections.
- Toolbox reference: A reference to the block type in the toolbox XML, so users can add it to the workspace.
The easiest way to build new block definitions is to use the Blockly Developer Tools. Since Blockly for Android only supports JSON formatted block definitions, set the factory's "Language Code" to JSON. Details on this format can be found here.
the block definition files are provided by
which returns a list of application asset paths. The block definitions can be
reloaded by calling
When using the raw
add block definitions via one of the
.json files can be loaded, though you should be sure the block type
IDs are unique.
Add Toolbox Reference
Once the system knows about your new blocks, you need to let your users know, too. The toolbox shows users what blocks are available to them. Blockly uses the same XML toolbox definition file as Blockly on the web, detailed here.
AbstractBlocklyActivity populates the Toolbox with the contents of the
asset file provided by
reload the toolbox (calling
You can also call any of the
In general, most blocks should be included in the toolbox, but some can be left out. This can be used to support deprecated blocks, teach individual concepts, or to hide blocks that currently can't be used. See Populate the Toolbox for more details.
Add Generator Function
See Use Custom Generators for more details.