微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

单击并按住bottomNavigationView 上的按钮会在其周围创建一个奇怪的“阴影”并显示一个黑框

如何解决单击并按住bottomNavigationView 上的按钮会在其周围创建一个奇怪的“阴影”并显示一个黑框

我创建了一个带有浮动操作按钮的底部导航视图,底部导航栏上的项目在点击或按住它们后表现得很奇怪:

as you can notice there is a shadow around the "settings" button + that gray box appears

我应该更改/禁用什么才能在单击按钮后摆脱按钮周围的“阴影”以及那个灰色框(按住按钮后出现)?

代码

  <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/bottomNavBar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/menu_final">

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="2dp"
            android:clickable="true"
            android:focusable="true"
            android:foregroundGravity="clip_horizontal"
            android:theme="@style/fab"
            app:srcCompat="@drawable/ic_add" />
    </com.google.android.material.bottomnavigation.BottomNavigationView>

样式:

    <style name="fab" parent="Widget.Design.FloatingActionButton">
        <item name="android:backgroundTint">@color/white</item>
        <item name="tint">@color/black</item>
    </style>

    <style name="bottomNavBar" parent="Widget.Design.BottomNavigationView">
        <item name="android:background">@color/ground</item>
    </style>

解决方法

尝试设置 app:itemRippleColor="@null"app:itemRippleColor="#0000"(透明)

在底部导航视图中

,

我终于修复了它(这可能不是最好的解决方案,但......它有效)

要移除阴影,您只需将 colorControlHighlight 和 colorControlActivated 设置为“@android:color/transparent”到底部导航栏

删除在按住按钮到活动添加后出现的框:

        bottomNavigationView.children.forEach {
            (it as? ViewGroup)?.children?.forEach {
                it.setOnLongClickListener { _ -> true }
            }
        }

source

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。