简体   繁体   English

如何使用浮动操作按钮创建底部导航

[英]How to create bottom navigation with floating action button

How to create this design如何创建此设计

在此处输入图像描述

I have used this code but not get expected result我使用了这段代码但没有得到预期的结果

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/colorPrimary"
        app:fabAlignmentMode="center" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_plus"
        app:backgroundTint="@android:color/transparent"
        app:fabAlignmentMode="center"
        app:fabCradleRoundedCornerRadius="2dp"
        app:layout_anchor="@id/bottom_app_bar" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

ic_plus.xml ic_plus.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <gradient
                android:angle="180"
                android:endColor="#FFFF8B00"
                android:startColor="#FFFF4806" />
            <size
                android:width="56dp"
                android:height="56dp" />
        </shape>
    </item>
    <item
        android:left="10dp"
        android:right="10dp">
        <shape android:shape="line">
            <stroke
                android:width="2dp"
                android:color="#ffffff" />
        </shape>
    </item>
    <item
        android:left="10dp"
        android:right="10dp">
        <rotate android:fromDegrees="90">
            <shape android:shape="line">
                <stroke
                    android:width="2dp"
                    android:color="#ffffff" />
            </shape>
        </rotate>
    </item>
</layer-list>

dimens.xml维度.xml

<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>

In MenifestMenifest

android:theme="@style/Theme.MaterialComponents.NoActionBar"

But I am getting this但我明白了

在此处输入图像描述

Any help will be appreciated.任何帮助将不胜感激。 Thanks谢谢

You have to add你必须添加

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        app:backgroundTint="@null"
        app:tint="@null"
        ../>

The default style tints the background and the icon.默认样式为背景和图标着色。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在带有缺口的底部导航栏中心添加浮动操作按钮? - How to add Floating action Button in Bottom Navigation Bar Center with notch? 浮动操作按钮块底部导航栏 - floating action button blocks bottom navigation bar 浮动动作按钮与Android中的底部导航重叠 - floating action button overlaping bottom navigation in android 如何在标签导航底部制作浮动按钮? - How make a floating button in tab navigation bottom? 隐藏在底部导航栏后面的 Android 浮动操作按钮 - Android floating action button hidden behind of bottom navigation bar 是否有将浮动操作按钮与底部导航视图相结合的库? - Is there a library to combine floating action button with bottom navigation view? 如何将浮动操作按钮对齐到结尾|底部 - How to align Floating Action Button to end|bottom 删除底部导航和浮动操作按钮之间的小层? - Remove small layer between bottom navigation and Floating action button? 底部导航栏浮动按钮,动作覆盖整个屏幕 - 如何做到这一点? - Bottom Navigation Bar Floating Button with action covering the whole screen - how to do this? 如何在导航抽屉中使用浮动操作按钮? - how to use floating action button with navigation drawer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM