![]() ![]() ![]() This is identical to the state list animator from the Button style, but I’ve changed the elevation and translationY values so that it sits higher than a standard button. Therefore, in order to change the elevation we have to override the stateListAnimator: ![]() The reason for this is that the stateListAnimator defined in the parent style (which provides the various states and animates between those states) has elevation and translateZ hard coded, so effectively override any values in the stye or layout. However, I found that changing the elevation of the FAB itself in either the style or layout made absolutely no difference. The guidelines state that a FAB should appear higher than other buttons as it is a primary action, so the elevation needs to be higher than a standard button. The only thing that I couldn’t get right was the elevation. When pressing the FAB, it would rise slightly to meet the touch – exactly as detailed in the material guidelines. ![]() In Android Studio you can right click the Project. The FAB had a shadow generated automatically – this is why we used a shape drawable earlier because the framework was able to determine the outline of the shape drawable and generate the appropriate shadow automagically. The FloatingActionButton widget in Flutter is a small circular icon button. This provided me with almost exactly the behaviour that I was looking for. Initially I extended this without overriding the stateListAnimator. One thing to note about is that we extend the Material.Button style, but there is a bit of a gotcha in here which is worth explaining. However, in this case, the FAB should be a fixed size, and width and height are common to all parent layouts, so it is safe to put them in the style to ensure consistency. Normally I would avoid putting any layout_* attributes in the style because the prefix means that they are related to the parent layout and not the view itself, so therefore are part of the layout and not the style. Here we specify the background tht we’ve just created, and also set the dimensions of the button. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |