首页 > 解决方案 > 如何使 ActionBar 在活动中不可见?

问题描述

我想让我的活动的 actionBar 不可见。hide()对我不起作用,因为它完全删除了 actionBar 并且活动在隐藏后不会保持视图的高度。

我怎样才能做到这一点?

编辑(代码更新):

布局.xml:

<LinearLayout
        android:id="@+id/top_bar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/detail_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_back_dark"
            android:contentDescription="@string/back_button"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:padding="16dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_gravity="center_vertical" />

        <TextView
            android:id="@+id/user_selected_name_surname"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Detail"
            android:textSize="22sp"
            android:gravity="center|start"/>

    </LinearLayout>

    <View
        android:id="@+id/top_bar_divider"
        android:layout_below="@id/notification_top_bar"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/grey_color"/>

在activity.java中,我简单地将线性布局和分隔线设置为INVISIBLE:

topBar.setVisibility(View.INVISIBLE);
topBarDivider.setVisibility(View.INVISIBLE);

标签: javaandroid-actionbar

解决方案


推荐阅读