@@ -59,79 +59,70 @@ Add the `SpeedDialView` to your layout:
59
59
60
60
#### Action items
61
61
Add the items to the ` SpeedDialView ` :
62
- ``` java
63
- SpeedDialView speedDialView = findViewById(R . id. speedDial);
62
+ ``` kotlin
63
+ val speedDialView = findViewById< SpeedDialView > (R .id.speedDial)
64
64
speedDialView.addActionItem(
65
- new SpeedDialActionItem .Builder (R . id. fab_link, R . drawable. ic_link_white_24dp)
66
- .create()
67
- );
68
-
65
+ SpeedDialActionItem .Builder (R .id.fab_no_label, R .drawable.ic_link_white_24dp)
66
+ .create())
69
67
```
70
68
71
69
If the color customization is not requested, it is also possible to inflate the Action items
72
70
form a Menu Resource:
73
- ``` java
74
- speedDialView. inflate(R . menu. menu_speed_dial);
71
+ ``` kotlin
72
+ speedDialView.inflate(R .menu.menu_speed_dial)
75
73
```
76
74
Only the attributes ` android:id ` , ` android:icon ` and ` android:title ` are supported.
77
75
78
76
#### Click listeners
79
77
Add the click listeners:
80
- ``` java
81
- speedDialView. setOnActionSelectedListener(new SpeedDialView .OnActionSelectedListener () {
82
- @Override
83
- public boolean onActionSelected (SpeedDialActionItem speedDialActionItem ) {
84
- switch (speedDialActionItem. getId()) {
85
- case R . id. fab_link:
86
- showToast(" Link action clicked!" );
87
- return false ; // true to keep the Speed Dial open
88
- default :
89
- return false ;
78
+ ``` kotlin
79
+ speedDialView.setOnActionSelectedListener(SpeedDialView .OnActionSelectedListener { actionItem ->
80
+ when (actionItem.id) {
81
+ R .id.fab_no_label -> {
82
+ showToast(" No label action clicked!\n Closing with animation" )
83
+ speedDialView.close() // To close the Speed Dial with animation
84
+ return @OnActionSelectedListener true // false will close it without animation
90
85
}
91
86
}
92
- });
87
+ false
88
+ })
93
89
```
94
90
95
91
### Optional steps
96
92
#### Add the main action click listener
97
- ``` java
98
- speedDialView. setOnChangeListener(new SpeedDialView .OnChangeListener () {
99
- @Override
100
- public void onMainActionSelected () {
101
- // Call your main action here
102
- return false ; // true to keep the Speed Dial open
93
+ ``` kotlin
94
+ speedDialView.setOnChangeListener(object : SpeedDialView .OnChangeListener {
95
+ override fun onMainActionSelected (): Boolean {
96
+ showToast(" Main action clicked!" )
97
+ return false // True to keep the Speed Dial open
103
98
}
104
99
105
- @Override
106
- public void onToggleChanged (boolean isOpen ) {
107
- Log . d(TAG , " Speed dial toggle state changed. Open = " + isOpen);
100
+ override fun onToggleChanged (isOpen : Boolean ) {
101
+ Log .d(TAG , " Speed dial toggle state changed. Open = $isOpen " )
108
102
}
109
- });
103
+ })
110
104
```
111
105
112
106
#### Customizing the items
113
107
The ` SpeedDialActionItem.Builder ` provides several setters to customize the aspect of one item:
114
108
115
- ``` java
116
- mSpeedDialView. addActionItem(
117
- new SpeedDialActionItem .Builder (R . id. fab_custom_color, R . drawable. ic_custom_color)
118
- .setFabBackgroundColor(ResourcesCompat . getColor(getResources(), R . color. material_white_1000, getTheme()))
119
- .setFabImageTintColor(ResourcesCompat . getColor(getResources(), R . color. inbox_primary, getTheme()))
120
- .setLabel(getString(R . string. label_custom_color))
121
- .setLabelColor(Color . WHITE )
122
- .setLabelBackgroundColor(ResourcesCompat . getColor(getResources(), R . color. inbox_primary, getTheme()))
123
- .setLabelClickable(false )
124
- .create()
125
- );
109
+ ``` kotlin
110
+ speedDialView.addActionItem(SpeedDialActionItem .Builder (R .id.fab_custom_color, drawable)
111
+ .setFabBackgroundColor(ResourcesCompat .getColor(getResources(), R .color.material_white_1000, getTheme()))
112
+ .setFabImageTintColor(ResourcesCompat .getColor(getResources(), R .color.inbox_primary, getTheme()))
113
+ .setLabel(getString(R .string.label_custom_color))
114
+ .setLabelColor(Color .WHITE )
115
+ .setLabelBackgroundColor(ResourcesCompat .getColor(getResources(), R .color.inbox_primary, getTheme()))
116
+ .setLabelClickable(false )
117
+ .create())
126
118
```
127
119
Is is also possible to specify a theme to easily change the FAB background and ripple effect color:
128
120
129
- ``` java
130
- mSpeedDialView. addActionItem(
131
- new SpeedDialActionItem .Builder (R . id. fab_custom_theme, R . drawable. ic_theme_white_24dp)
132
- .setLabel(getString(R . string. label_custom_theme))
133
- .setTheme(R . style. AppTheme_Purple )
134
- .create());
121
+ ``` kotlin
122
+ speedDialView.addActionItem(SpeedDialActionItem .Builder (R .id.fab_custom_theme, R .drawable.ic_theme_white_24dp)
123
+ .setLabel(getString(R .string.label_custom_theme))
124
+ .setTheme(R .style.AppTheme_Purple )
125
+ .create())
135
126
```
136
127
``` xml
137
128
<style name =" AppTheme.Purple" parent =" AppTheme" >
@@ -162,9 +153,9 @@ and then provide the instance of that layout to the `SpeedDialView`:
162
153
app : sdOverlayLayout =" @id/overlay" />
163
154
```
164
155
or
165
- ``` java
166
- SpeedDialOverlayLayout overlayLayout = findViewById(R . id. overlay);
167
- mSpeedDialView . setSpeedDialOverlayLayout(overlayLayout);
156
+ ``` kotlin
157
+ val overlayLayout = findViewById< SpeedDialOverlayLayout > (R .id.overlay)
158
+ speedDialView .setSpeedDialOverlayLayout(overlayLayout)
168
159
```
169
160
170
161
#### Hiding the FAB when scrolling a ` RecyclerView ` or a ` NestedScrollView `
@@ -180,20 +171,20 @@ the convenience string resource `@string/speeddial_scrolling_view_snackbar_behav
180
171
```
181
172
182
173
Or programmatically:
183
- ``` java
184
- CoordinatorLayout . LayoutParams params = ( CoordinatorLayout . LayoutParams ) speedDialView . getLayoutParams();
185
- params. setBehavior( new SpeedDialView .ScrollingViewSnackbarBehavior ());
186
- speedDialView. requestLayout();
174
+ ``` kotlin
175
+ val params = speedDialView.layoutParams as CoordinatorLayout . LayoutParams
176
+ params.behavior = SpeedDialView .ScrollingViewSnackbarBehavior ()
177
+ speedDialView.requestLayout()
187
178
```
188
179
189
180
NB: for the behaviors to work, ` SpeedDialView ` needs to be a direct child of ` CoordinatorLayout `
190
181
191
182
#### Disabling ` SnackbarBehavior `
192
183
Since the ` SnackbarBehavior ` is enabled by default and, afaik, it is not possible to remove a Behavior, simply use apply the ` SpeedDialView.NoBehavior ` instead:
193
- ``` java
194
- CoordinatorLayout . LayoutParams params = ( CoordinatorLayout . LayoutParams ) speedDialView . getLayoutParams();
195
- params. setBehavior( new SpeedDialView .NoBehavior ());
196
- speedDialView. requestLayout();
184
+ ``` kotlin
185
+ val params = speedDialView.layoutParams as CoordinatorLayout . LayoutParams
186
+ params.behavior = SpeedDialView .NoBehavior ()
187
+ speedDialView.requestLayout()
197
188
```
198
189
199
190
### Sample project
@@ -250,7 +241,7 @@ This project is based on [floating-action-menu by ArthurGhazaryan](https://githu
250
241
251
242
## Licenses
252
243
```
253
- Copyright 2018 Roberto Leinardi.
244
+ Copyright 2019 Roberto Leinardi.
254
245
255
246
Licensed to the Apache Software Foundation (ASF) under one or more contributor
256
247
license agreements. See the NOTICE file distributed with this work for
0 commit comments