【问题标题】:Androidx material design bottom appbar how to hide back arrowAndroidx材料设计底部appbar如何隐藏后退箭头
【发布时间】: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_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>

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

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

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

nav.navigate(R.id.verificationsfragment);

查看截图:

【问题讨论】:

  • 你能提供一张发生了什么的截图和你写的一些代码吗?
  • 添加了截图和一些代码。

标签: android material-design android-bottomappbar


【解决方案1】:

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

getSupportActionBar.setDisplayHomeAsUpEnabled(false);

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

希望对你有帮助!

【讨论】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 2014-12-23
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多