1

我有一个BottomAppBar来自新材料设计的FAB。它BottomAppBar有一个特定的菜单,其中包含 2 个项目和一个导航图标。问题是,我将底部应用栏颜色设置为白色,图标也是白色。我怎样才能改变这个?这是我的activity_layout

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

        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:hideOnScroll="true"
            style="@style/BottomAppBarTheme"
            app:menu="@menu/bottom_app_bar"
            app:navigationIcon="@drawable/ic_menu_black_24"
            app:fabCradleMargin="10dp" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_add_white_24"
            app:layout_anchor="@id/bottomAppBar"
            app:shapeAppearance="@style/FabDiamondOverlay"

            />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

这是我的styles.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryDark">@color/primaryDarkColor</item>
        <item name="colorAccent">@color/secondaryColor</item>
        <item name="android:actionMenuTextColor">@android:color/black</item>

    </style>

    <style name="FabDiamondOverlay" parent="">
        <item name="cornerFamily">cut</item>
        <item name="cornerSize">8dp</item>
    </style>

    <style name="BottomAppBarTheme" parent="Widget.MaterialComponents.BottomAppBar.Colored">
        <item name="android:itemBackground">@android:color/black</item>
    </style>

这是底部应用栏的图像(带有白色的图标...): 在此处输入图像描述

4

1 回答 1

2

您可以使用:

<com.google.android.material.bottomappbar.BottomAppBar
    android:theme="@style/BottomAppBarOverlay"
     .../>

和:

<style name="BottomAppBarOverlay">
    <item name="colorControlNormal">@color/...</item>
</style>

在此处输入图像描述

您还可以使用:

<com.google.android.material.bottomappbar.BottomAppBar
    style="@style/MyBottomAppBar"
    ..>

和:

<style name="MyBottomAppBar" parent="Widget.MaterialComponents.BottomAppBar">
    <item name="materialThemeOverlay">@style/ThemeOverlay.BottomAppBar</item>
</style>

<style name="ThemeOverlay.BottomAppBar" parent="ThemeOverlay.MaterialComponents.BottomAppBar.Primary">
    <item name="colorOnPrimary">@color/.....</item>
</style>
于 2020-07-10T21:41:08.210 回答