安卓 : Add rounded corners to BottomAppBar with circular anchored FAB

标签 android bottomnavigationview custom-view android-bottomnav android-bottomappbar

我想实现与此 View 类似的东西,底部导航具有左上角和右上角圆角半径以及锚定的 FAB enter image description here

最佳答案

您可以使用标准的 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());

enter image description here

关于新的 RelativeCornerSize(0.5f) 的注意事项:它在 1.2.0-beta01 中发生了变化。在 new RelativeCornerSize(50)

之前

关于安卓 : Add rounded corners to BottomAppBar with circular anchored FAB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61837446/

相关文章:

android - java.io.IOException : Permission denied cannot create file 异常

android - 定义位图字节数并设置位图缓冲区的限制

android - Device Owner Android 应用程序的 OTA 更新(Kiosk 模式)

ios - 从自定义 View 加载表格单元格内容

android - 在继承 View 的自定义 View 中添加 TextView

c# - 在 Xamarin.Forms 中添加方向更改布局

android - 如何在 Android 导航组件中管理 BottomNavigationView 后台堆栈

android - 在 BottomNavigationView 中选择时如何为每个项目使用不同的颜色?

android-fragments - 在底部导航片段之间切换时工具栏会闪烁

ios - 在 swift 3 中使用自定义 View 选择多个日期范围