Androidx材料设计底部appbar如何隐藏后退箭头

Posted

技术标签:

【中文标题】Androidx材料设计底部appbar如何隐藏后退箭头【英文标题】:Androidx material design bottom appbar how to hide back arrow 【发布时间】:2020-07-01 11:47:00 【问题描述】:

我正在使用带有片段导航的谷歌材料设计底部应用栏。 我没有使用 NavigationIcon,但是,当单击项目时,会出现一个后退导航箭头。 如何隐藏导航? 这是主要活动 xml,自定义菜单项以显示带有图标的标题:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_
        android:layout_>
        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_
            android:layout_
            android:layout_gravity="center_vertical"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toTopOf="@id/coordinatorLayout"
            app:layout_constraintEnd_toStartOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0"
            app:navGraph="@navigation/mobile_navigation" />
        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id="@+id/coordinatorLayout"
            android:layout_
            android:layout_
            app:layout_constraintBottom_toBottomOf="parent">

            <com.google.android.material.bottomappbar.BottomAppBar
                android:id="@+id/bottom_app_bar"
                android:layout_
                android:layout_
                android:layout_gravity="bottom"
                app:backgroundTint="@color/toolbarbackgroung"
                android:animateLayoutChanges="true"
                app:fabAlignmentMode="center"
                app:fabAnimationMode="slide"
                app:hideOnScroll="true">
                <RelativeLayout
                    android:layout_
                    android:layout_>
                    <TextView
                        android:id="@+id/verificationscmd"
                        android:layout_
                        android:layout_
                        android:layout_alignParentLeft="true"
                        android:layout_marginStart="10dp"
                        android:layout_marginEnd="10dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginBottom="5dp"
                        android:clickable="true"
                        android:focusable="true"
                        android:background="?android:attr/selectableItemBackground"
                        android:text="@string/title_verifications"
                        android:drawableTop="@drawable/ic_notifications"/>
                    <TextView
                        android:id="@+id/configurationcmd"
                        android:layout_
                        android:layout_
                        android:layout_alignParentRight="true"
                        android:layout_marginStart="10dp"
                        android:layout_marginEnd="10dp"
                        android:layout_marginTop="5dp"
                        android:layout_marginBottom="5dp"
                        android:clickable="true"
                        android:focusable="true"
                        android:background="?android:attr/selectableItemBackground"
                        android:text="@string/title_config"
                        android:drawableTop="@drawable/ic_gear"/>


                </RelativeLayout>

            </com.google.android.material.bottomappbar.BottomAppBar>

            <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/principalbutton"
    android:layout_
    android:layout_
    style="@style/Widget.MaterialComponents.FloatingActionButton"
    app:backgroundTint="@color/primaryColor"
    app:elevation="8dp"
    app:fabCradleMargin="2dp"
    app:fabCradleRoundedCornerRadius="2dp"
    app:fabCustomSize="54dp"
    app:layout_anchor="@id/bottom_app_bar"
    app:maxImageSize="32dp"
    app:tint="@color/lightcolor"
    app:srcCompat="@drawable/ic_plus_symbol" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout></androidx.constraintlayout.widget.ConstraintLayout>

在 onCreate 活动事件中创建 Bootm 应用栏:

bar = (BottomAppBar) findViewById(R.id.bottom_app_bar);
setSupportActionBar(bar);

片段显示在点击监听器中:

nav.navigate(R.id.verificationsfragment);

查看截图:

【问题讨论】:

你能提供一张发生了什么的截图和你写的一些代码吗? 添加了截图和一些代码。 【参考方案1】:

在你的activity中,尝试在setSupportActionBar之后添加这行代码:

getSupportActionBar.setDisplayHomeAsUpEnabled(false);

这应该会移除后退箭头按钮。

希望对你有帮助!

【讨论】:

这条线没有帮助。我找到的唯一解决方案是 set bar.setNavigationIcon(null);在每笔交易中,但 onclick 会在图标项中产生奇怪的运动 好的。你也试过getSupportActionBar().setHomeButtonEnabled(false);吗?【参考方案2】:

最后我解决了在底部导航栏中的底部导航视图,所以我有底部导航方面,带有 floatinActionButtonIntegration 和底部导航视图功能。

【讨论】:

以上是关于Androidx材料设计底部appbar如何隐藏后退箭头的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Flutter 中创建带有底部彩色边框的 AppBar?

Flutter:如何仅在滚动后显示 AppBar?

Tab指示器不再位于AppBarLayout的底部。该选项卡是定制的选项卡

如何在 Flutter 中使用 GestureDetector 隐藏 appBar?

如何从 AppBar 中删除或隐藏后退图标 [重复]

在导航组件中隐藏工具栏或底部导航栏