Android : 使用圆形锚定 FAB 向 BottomAppBar 添加圆角
Android : Add rounded corners to BottomAppBar with circular anchored FAB
我想实现与此视图类似的效果,底部导航具有左上角和右上角圆角半径以及锚定的 FAB
您可以使用标准 BottomAppBar
:
<com.google.android.material.bottomappbar.BottomAppBar
android:layout_margin="xxdp"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="2dp"
app:fabCradleVerticalOffset="8dp"
app:fabCradleMargin="8dp" />
然后更改ShapeAppearanceModel
:
BottomAppBar bottomAppBar = findViewById(R.id.bottomAppBar);
MaterialShapeDrawable bottomBarBackground = (MaterialShapeDrawable) bottomAppBar.getBackground();
bottomBarBackground.setShapeAppearanceModel(
bottomBarBackground.getShapeAppearanceModel()
.toBuilder()
.setAllCorners(new RoundedCornerTreatment()).setAllCornerSizes(new RelativeCornerSize(0.5f))
.build());
关于新 RelativeCornerSize(0.5f)
的注意事项:它在 1.2.0-beta01
中发生了变化。之前是new RelativeCornerSize(50)
我想实现与此视图类似的效果,底部导航具有左上角和右上角圆角半径以及锚定的 FAB
您可以使用标准 BottomAppBar
:
<com.google.android.material.bottomappbar.BottomAppBar
android:layout_margin="xxdp"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="2dp"
app:fabCradleVerticalOffset="8dp"
app:fabCradleMargin="8dp" />
然后更改ShapeAppearanceModel
:
BottomAppBar bottomAppBar = findViewById(R.id.bottomAppBar);
MaterialShapeDrawable bottomBarBackground = (MaterialShapeDrawable) bottomAppBar.getBackground();
bottomBarBackground.setShapeAppearanceModel(
bottomBarBackground.getShapeAppearanceModel()
.toBuilder()
.setAllCorners(new RoundedCornerTreatment()).setAllCornerSizes(new RelativeCornerSize(0.5f))
.build());
关于新 RelativeCornerSize(0.5f)
的注意事项:它在 1.2.0-beta01
中发生了变化。之前是new RelativeCornerSize(50)