Instead of having a regular button, we are able to create a button that toggles whenever it is clicked. The logic of doing so works similarly to our enable/visible, but with pressed instead. Note that this requires Alloy version 1.8.0.0 or newer.
When toggling a button, there is a true element and a false element. Compared to normal buttons, commands for the "true"-click must be inside an XML element <True/>, likewise the "false"-click must be a <False/> element.
Supported elements:
- Document properties: documentprop
- Inverse Document properties: !documentprop
- Registry key: registry
- Inverse registry key: !registry
Examples of usage
Show/hide paragraph mark
With the button below, the user is able to toggle whether paragraph marks in a document is shown or hidden. The button is depended on a document property called ParagraphMark. The true element inserts the document property, while the false element removes the document property concerned.
<ToggleButton label="Show/Hide" pressed="BaseExtensions:any" pressed-1-type="documentprop" pressed-1-key-1="ParagraphMark">
<True>
<Cmd case="BaseExtensions:content-create" type="document-property" name="ParagraphMark" value="True" />
<Cmd case="BaseExtensions:show-hide-formatting-marks" paragraphMarks="true"/>
</True>
<False>
<Cmd case="BaseExtensions:remove-doc-prop" name="ParagraphMark"/>
<Cmd case="BaseExtensions:show-hide-formatting-marks" paragraphMarks="false"/>
</False>
</ToggleButton>Read registry key to determine whether a check-mark should be displayed
Here, the toggle button is used as a user setting to define which set of chart templates to use. A check-mark will appear next to the selected option. When using registry as element, follow these rules:
- *-1-type =
registryor!registry - *-1-key-1 = Path in current user
- *-1-key-2 = Name of value
- *-1-value-* = Any value that should match
<ToggleButton label="Standard" pressed="BaseExtensions:any" pressed-1-type="REGISTRY"pressed-1-key-1="Software\Alloy" pressed-1-key-2="SDCharts3.Redirect" pressed-1-value-1="SkabelonDesign.CorporateCharts3">
<True>
<Cmd case="BaseExtensions:update-registry" path="Software\Alloy" name="SDCharts3.Redirect" type="string" valueDefault="SkabelonDesign.CorporateCharts3"/>
</True>
<False>
</False>
</ToggleButton>Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article