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

时间:2020-03-20 10:34:34

标签: android material-design android-bottomappbar

我正在将Google Material Design底部应用栏与片段导航一起使用。 我没有使用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_width="match_parent"
        android:layout_height="match_parent">
        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            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_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent">

            <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/toolbarbackgroung"
                android:animateLayoutChanges="true"
                app:fabAlignmentMode="center"
                app:fabAnimationMode="slide"
                app:hideOnScroll="true">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <TextView
                        android:id="@+id/verificationscmd"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        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_width="wrap_content"
                        android:layout_height="wrap_content"
                        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_width="wrap_content"
    android:layout_height="wrap_content"
    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>

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

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

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

nav.navigate(R.id.verificationsfragment);

查看屏幕截图:

before click verifications after click

2 个答案:

答案 0 :(得分:0)

在您的活动中,尝试在setSupportActionBar之后添加以下代码行:

getSupportActionBar.setDisplayHomeAsUpEnabled(false);

这应该删除后退箭头按钮。

希望有帮助!

答案 1 :(得分:0)

最后,我在bottomnavigationBar内使用BottomNavigationView进行了解析,所以我具有BottomNavigation方面,具有floatinActionButtonIntegration和BottomNavigationView功能。