[英]Bottom navigation bar - rectangle action button
You can use the app:shapeAppearanceOverlay
attribute to achieve a square button and the app:fabCradleVerticalOffset
attribute to change the distance of the FAB to the BottomAppBar
.您可以使用
app:shapeAppearanceOverlay
属性实现方形按钮,使用app:fabCradleVerticalOffset
属性更改 FAB 到BottomAppBar
的距离。
Something like:就像是:
<com.google.android.material.bottomappbar.BottomAppBar
app:fabCradleVerticalOffset="16dp"
app:fabCradleRoundedCornerRadius="0dp"
app:fabCradleMargin="0dp"
..>
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:shapeAppearanceOverlay="@style/SquareFloatingShapeOVerlay"
../>
with:和:
<style name="SquareFloatingShapeOVerlay" parent="">
<item name="cornerSize">0dp</item>
</style>
If you want a rectangular shape you can use a ExtendedFloatingActionButton
instead of the FloatingActionButton
.如果你想要一个矩形,你可以使用
ExtendedFloatingActionButton
而不是FloatingActionButton
。
Something like:就像是:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
app:layout_anchor="@id/bottom_app_bar"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlayExtended"
../>
with:和:
<style name="ShapeAppearanceOverlayExtended" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">0dp</item>
</style>
Note: it requires the version 1.1.0
of the Material Components Library.注意:它需要材质组件库的
1.1.0
版本。
Try this: If you are using FloatingActionButton
试试这个:如果你正在使用
FloatingActionButton
app:borderWidth="0dp"
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
android:layout_marginRight="20dp"
app:fabSize="normal"
android:elevation="@dimen/fab_elevation"
android:background="#000000"
app:borderWidth="0dp"
android:stateListAnimator="@animator/fab_anim"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
Hope this will help !希望这会有所帮助!
To change the shape of the Floating Action Button, you can create a separate resource file in the drawable folder for eg: shape.xml
as-要更改浮动操作按钮的形状,您可以在 drawable 文件夹中创建一个单独的资源文件,例如:
shape.xml
as-
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
and then in Floating Action Button add the following property:然后在浮动操作按钮中添加以下属性:
android:background="@drawable/shape"
Also, you can use margin to move it higher.此外,您可以使用保证金将其移得更高。
Use elevation
attribute to FAB对 FAB 使用
elevation
属性
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/nav_items" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="40dp"
android:clickable="true"
app:elevation="8dp"
app:srcCompat="@android:drawable/ic_input_add" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.