作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我像这样使用来自谷歌的 BottomAppBar
:
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/vNavigationBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
自定义底栏是平的,我需要在底栏上添加圆角(如下图示例)
我应该怎么做才能使它以这种方式工作?
最佳答案
BottomAppBar 与 MaterialShapeDrawable
配合使用,您可以为其应用圆角(使用 RoundedCornerTreatment
)。
在你的布局中:
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/..."
../>
然后在代码中定义:
//Corner radius
float radius = getResources().getDimension(R.dimen.default_corner_radius);
BottomAppBar bottomAppBar = findViewById(R.id.bottom_app_bar);
MaterialShapeDrawable bottomBarBackground = (MaterialShapeDrawable) bottomAppBar.getBackground();
bottomBarBackground.setShapeAppearanceModel(
bottomBarBackground.getShapeAppearanceModel()
.toBuilder()
.setTopRightCorner(CornerFamily.ROUNDED,radius)
.setTopLeftCorner(CornerFamily.ROUNDED,radius)
.build());
它也适用于 fabCradle
:
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
app:fabAlignmentMode="center"
app:fabCradleVerticalOffset="8dp"
app:fabCradleMargin="8dp"
.../>
它需要版本 1.1.0。
关于android - 如何将带有圆角的android BottomAppBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54406436/
我是一名优秀的程序员,十分优秀!