example Android Buttons title:
Add a concise (1-2 sentence) description of the component here starting with the one-line definition from the design/guidance page. The corresponding design document should have a full description.
Add a link to the corresponding design page that the component (helps) implement.
For example:
Buttons allow users to take actions and make choices with a single tap. Buttons can be customized to meet your style requirements.
For more information, go to the Buttons guidance page.
If there are component variants, list them here and link to the local anchor link for its section.
Insert any related graphics: show instead of say.
example images from Buttons:
If there are any instructions on using the component that applies to all component variants (for example, installation or theming), include them here.
For example, for the iOS buttons component:
Before using the
MDCButtons
component to implement its variants you must installMCDButtons
. In your source files import the component, and then apply your theme:
Install
MDCButtons
- Use CocoaPods to install
MDCButtons
- Add the following to your
Podfile
:pod MaterialComponents/Buttons
- Run the installer:
pod installImport
MDCButtons
and MDC buttons theming and initializeMDCButtons
usingalloc
/init
. Initialize your theme before applying it to your button.Note For more information about themes, go to the Theming page for iOS.
Swift
import MaterialComponents.MaterialButtons import MaterialComponents.MaterialButtons_Theming /*...*/ let <local theme name> = <theme name> let button = MDCButton()Objective-C
#import "MaterialButtons.h" #import <MaterialComponentsBeta/MaterialButtons+Theming.h> /*...*/ <theme name> *<local theme name> = [[<theme name> alloc] init]; MDCButton *button = [[MDCButton alloc] init];Apply accessibility settings To help make your buttons usable to as many users as possible:
- Set an appropriate
accessibilityLabel
value if your button does not have a title or only has an icon. Objective-CSwiftbutton.accessibilityLabel = @"Create";
button.accessibilityLabel = "Create"
Divide the component API into its variants, preferably as described in the [material.io/components] pages.
For example buttons is divided into the following 3rd tier (###
header) sections based on its variants:
- Text button
- Outlined button
- Contained button
- Toggle button
Whereas cards is divided into:
- Behavior
- Actions
- Card collections
Each section should have a 3rd tier header. Add 1-2 sentences from the material.io website that describes when and how to use the component.
Important If your platform does not support a particular variant, EXPLICITLY STATE THAT IT DOESN'T.
Example: Android Text Button
Text buttons are typically used for less-pronounced actions, including those located: * In dialogs * In cards In cards, text buttons help maintain an emphasis on card content.
...
Toggle button is divided into two subvariants:
- Toggle button group
- Icon button <img src"images/button-icon-toggle.png" alt="Icon toggle button group example">
Android currently does not support toggle button groups. If you need a framework for a toggle button group, use <example framework>.
To add an icon button ...
Each example should have 1-2 sentences to describe the example. The example should include an image rendering whatever sample code is included:
Example: Android Text Button
The APIs section should have the following:
- Links to the applicable API(s) listed from highest level to lowest level
- Provide example source code that can generate the example in the image. Mention any themes/settings used.
Example: Android Button
<com.google.android.material.button.MaterialButton android:id="@+id/material_text_button" style="@style/Widget.MaterialComponents.Button.TextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text_button_label_enabled"/>Outline buttons are medium-emphasis buttons. They contain actions that are important, but aren’t the primary action in an app.
<com.google.android.material.button.MaterialButton android:id="@+id/material_text_button" style="@style/Widget.MaterialComponents.Button.OutlinedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/outlined_button_label_enabled"/>Contained buttons are high-emphasis, distinguished by their use of elevation and fill. They contain actions that are primary to your app.
Note Elevated
MaterialButtons
have a shadow that can extend outside the bounds of the button. For this reason, the wrapping parent element should set to android:clipToPadding="false" in cases where the button shadow could be clipped by the parent bounds.<com.google.android.material.button.MaterialButton android:id="@+id/material_button" style="@style/Widget.MaterialComponents.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_label_enabled"/><GridLayout android:id="@+id/grid" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:padding="16dp" android:clipToPadding="false" android:columnCount="2"> <com.google.android.material.button.MaterialButton android:id="@+id/material_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_label_enabled"/> <Space/> </GridLayout>The toggle button is a
ViewGroup
that groups together severalMaterialButton
<com.google.android.material.button.MaterialButtonToggleGroup xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toggle_button_group" android:layout_width="wrap_content" android:layout_height="wrap_content"> <com.google.android.material.button.MaterialButton style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_label_private"/> <com.google.android.material.button.MaterialButton style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_label_team"/> <com.google.android.material.button.MaterialButton style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_label_everyone"/> <com.google.android.material.button.MaterialButton style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_label_custom"/> </com.google.android.material.button.MaterialButtonToggleGroup>```