or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

buttons-and-selection.mdfeedback-and-communication.mdindex.mdinput-and-forms.mdlayout-and-containers.mdnavigation-components.mdpickers-and-selection.mdtheming-and-styling.md

index.mddocs/

0

# Material Components for Android

1

2

Material Components for Android (MDC-Android) is Google's official implementation of Material Design components for Android applications. It provides a comprehensive library of UI components including buttons, cards, navigation elements, text fields, dialogs, and many others that follow Material Design guidelines. The library offers extensive theming capabilities, supports Material You dynamic color, includes advanced animations and transitions, and provides accessibility features out of the box.

3

4

## Package Information

5

6

- **Package Name**: com.google.android.material:material

7

- **Package Type**: maven

8

- **Language**: Java

9

- **Installation**: Add to your `build.gradle` file:

10

```gradle

11

implementation 'com.google.android.material:material:1.14.0-alpha04'

12

```

13

14

## Core Imports

15

16

```java

17

import com.google.android.material.button.MaterialButton;

18

import com.google.android.material.card.MaterialCardView;

19

import com.google.android.material.textfield.TextInputLayout;

20

import com.google.android.material.snackbar.Snackbar;

21

import com.google.android.material.floatingactionbutton.FloatingActionButton;

22

```

23

24

## Basic Usage

25

26

```java

27

// Create a Material button

28

MaterialButton button = new MaterialButton(context);

29

button.setText("Click Me");

30

button.setIcon(getDrawable(R.drawable.ic_star));

31

button.setOnClickListener(v -> {

32

// Show a snackbar

33

Snackbar.make(v, "Button clicked!", Snackbar.LENGTH_SHORT).show();

34

});

35

36

// Create a Material card

37

MaterialCardView card = new MaterialCardView(context);

38

card.setStrokeWidth(2);

39

card.setStrokeColor(ContextCompat.getColor(context, R.color.stroke_color));

40

card.setCheckable(true);

41

42

// Create a text input field

43

TextInputLayout textInput = new TextInputLayout(context);

44

textInput.setHint("Enter your name");

45

textInput.setHelperText("This field is required");

46

```

47

48

## Architecture

49

50

Material Components for Android is built around several key design patterns:

51

52

- **Material Theming**: All components support Material Design theming through style attributes and theme overlays

53

- **Shape Theming**: Components can be customized using `ShapeAppearanceModel` for consistent shape language

54

- **Color System**: Built-in support for Material Design color roles and dynamic colors (Android 12+)

55

- **Motion System**: Components include built-in animations following Material motion principles

56

- **Accessibility**: All components include semantic accessibility support and screen reader compatibility

57

- **State Management**: Consistent state handling across components (enabled, disabled, checked, selected, etc.)

58

59

## Capabilities

60

61

### Buttons and Selection Controls

62

63

Core input controls including buttons, chips, checkboxes, radio buttons, and switches with Material Design styling and behavior.

64

65

```java { .api }

66

public class MaterialButton extends AppCompatButton {

67

public MaterialButton(Context context);

68

public void setIcon(Drawable icon);

69

public void setIconTint(ColorStateList iconTint);

70

public void setStrokeColor(ColorStateList strokeColor);

71

public void setStrokeWidth(int strokeWidth);

72

public void setCornerRadius(int cornerRadius);

73

}

74

```

75

76

[Buttons and Selection Controls](./buttons-and-selection.md)

77

78

### Navigation Components

79

80

Navigation elements including bottom navigation, navigation drawer, navigation rail, tabs, app bars, and search components for organizing app structure.

81

82

```java { .api }

83

public class BottomNavigationView extends NavigationBarView {

84

public BottomNavigationView(Context context);

85

public void setOnNavigationItemSelectedListener(OnNavigationItemSelectedListener listener);

86

public Menu getMenu();

87

public void setSelectedItemId(@IdRes int itemId);

88

}

89

```

90

91

[Navigation Components](./navigation-components.md)

92

93

### Input and Forms

94

95

Text input components, sliders, and form-related elements for collecting and validating user input.

96

97

```java { .api }

98

public class TextInputLayout extends LinearLayout {

99

public TextInputLayout(Context context);

100

public void setHint(CharSequence hint);

101

public void setError(CharSequence error);

102

public void setHelperText(CharSequence helperText);

103

public EditText getEditText();

104

}

105

```

106

107

[Input and Forms](./input-and-forms.md)

108

109

### Layout and Containers

110

111

Container components including cards, sheets, app bars, and layout utilities for organizing content.

112

113

```java { .api }

114

public class MaterialCardView extends CardView {

115

public MaterialCardView(Context context);

116

public void setStrokeColor(@ColorInt int color);

117

public void setStrokeWidth(@Dimension int strokeWidth);

118

public void setCheckable(boolean checkable);

119

public void setChecked(boolean checked);

120

}

121

```

122

123

[Layout and Containers](./layout-and-containers.md)

124

125

### Feedback and Communication

126

127

Components for providing feedback including snackbars, dialogs, progress indicators, badges, and tooltips.

128

129

```java { .api }

130

public class Snackbar extends BaseTransientBottomBar<Snackbar> {

131

public static Snackbar make(View view, CharSequence text, int duration);

132

public Snackbar setAction(CharSequence text, View.OnClickListener listener);

133

public Snackbar setActionTextColor(@ColorInt int color);

134

public void show();

135

}

136

```

137

138

[Feedback and Communication](./feedback-and-communication.md)

139

140

### Pickers and Selection

141

142

Date and time pickers with Material Design styling for temporal data selection.

143

144

```java { .api }

145

public class MaterialDatePicker<S> extends DialogFragment {

146

public static Builder<Long> datePicker();

147

public static Builder<Pair<Long, Long>> dateRangePicker();

148

public S getSelection();

149

public void addOnPositiveButtonClickListener(MaterialPickerOnPositiveButtonClickListener<S> listener);

150

}

151

```

152

153

[Pickers and Selection](./pickers-and-selection.md)

154

155

### Theming and Styling

156

157

Comprehensive theming system including colors, shapes, elevation, and dynamic theming support.

158

159

```java { .api }

160

public class MaterialColors {

161

public static int getColor(Context context, @AttrRes int colorAttributeResId, int defaultValue);

162

public static ColorStateList getColorStateList(Context context, @AttrRes int colorAttributeResId);

163

public static int layer(@ColorInt int backgroundColor, @ColorInt int overlayColor, @FloatRange float overlayAlpha);

164

}

165

```

166

167

[Theming and Styling](./theming-and-styling.md)

168

169

## Core Types

170

171

```java { .api }

172

// Shape appearance for customizing component shapes

173

public class ShapeAppearanceModel {

174

public static Builder builder();

175

public CornerTreatment getTopLeftCorner();

176

public CornerSize getTopLeftCornerSize();

177

}

178

179

// Color state lists for component theming

180

public interface ColorStateList {

181

int getColorForState(int[] stateSet, int defaultColor);

182

}

183

184

// Common listener interfaces

185

public interface OnNavigationItemSelectedListener {

186

boolean onNavigationItemSelected(@NonNull MenuItem item);

187

}

188

189

public interface OnClickListener {

190

void onClick(View v);

191

}

192

```

193

194

## Constants

195

196

```java { .api }

197

// Animation modes

198

public static final int ANIMATION_MODE_SLIDE = 0;

199

public static final int ANIMATION_MODE_FADE = 1;

200

201

// Label visibility modes

202

public static final int LABEL_VISIBILITY_AUTO = -1;

203

public static final int LABEL_VISIBILITY_SELECTED = 0;

204

public static final int LABEL_VISIBILITY_LABELED = 1;

205

public static final int LABEL_VISIBILITY_UNLABELED = 2;

206

207

// Snackbar durations

208

public static final int LENGTH_INDEFINITE = -2;

209

public static final int LENGTH_SHORT = -1;

210

public static final int LENGTH_LONG = 0;

211

```