如何在 Android Studio 的 Material Design 组件中禁用或自定义阴影效果

问题描述 投票:0回答:1

我正在使用 Android Studio 开发 Android 应用程序,并且我正在使用 Material Design 组件,特别是

BottomNavigationView
。我想禁用或自定义此
BottomNavigationView
上的阴影效果。我尝试直接在布局 XML 文件中设置
android:elevation="0dp"
,但阴影效果仍然存在。如何正确禁用或调整 Material Design 组件(如
BottomNavigationView
)的阴影效果?picture of the effect that I dont want

这是我尝试过的布局 XML 代码:

<com.google.android.material.bottomnavigation.BottomNavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/footer_menu"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    app:itemIconTint="@color/selector_footer"
    app:labelVisibilityMode="unlabeled"
    android:background="@color/white"
    app:menu="@menu/footer_menu"
    app:itemIconSize="32dp"/>

这就是

selector_footer.xml
的内容:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/color_button"
        android:state_checked="true"/>

    <item android:color="@color/color_button_before_pressed"
        android:state_checked="false"/>
</selector>
android bottomnavigationview material-components-android android-bottomnav android-bottomnavigationview
1个回答
0
投票

所以我遇到了与你看到的同样的问题这里。我找到了一个简单的解决办法。

您只需要更改项目的主题,然后它就会消失。在您当前的项目中在 res alues hemes 下检查这一点并设置以下主题。

<resources>
    <!-- MyApplication is your application. you only need to change the parent theme -->
    <style name="Base.Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.NoActionBar">

那就解决了。只需更改父部分即可。

我希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.