【问题标题】:How to create bottom navigation with floating action button如何使用浮动操作按钮创建底部导航
【发布时间】:2024-04-13 14:10:01
【问题描述】:

如何创建此设计

我已经使用了这段代码,但没有得到预期的结果

<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

<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

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

Menifest

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

但我得到了这个

任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: android android-layout android-theme floating-action-button material-components-android


    【解决方案1】:

    你必须添加

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

    默认样式为背景和图标着色。

    【讨论】:

    • 谢谢,浮动操作按钮背景来了
    • 我知道如何在BottomAppBar中添加主页和分享项目吗?
    • @ShivamKumar 如果您想在问题中发布相同的布局,您必须在 BottomAppBar 内使用 BottomNavigationView
    • 如果我使用了BottomNavigationView,那么它会隐藏FloatingActionButton
    • 太棒了。同时我需要知道如何通过 Xamarin Forms 来做到这一点。
    最近更新 更多