【问题标题】:Android: Make Actionbar overlap Activity layoutAndroid:使Actionbar重叠Activity布局
【发布时间】:2013-01-11 15:33:49
【问题描述】:

我有一个隐藏 Actionbar 的活动,当我单击按钮时,我希望它可见,但我不希望布局活动向下滚动,该栏必须与其重叠。 我怎么能做这样的事情?

隐藏我使用的栏

actionbar.hide();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

并使其可见:

actionbar.show();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

我的布局只是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <MyPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    <MyPager>

</RelativeLayout>

提前致谢。

【问题讨论】:

  • 粘贴一些代码或布局,根据这个描述很难说。

标签: android android-activity android-actionbar


【解决方案1】:

您可能正在寻找ActionBar 覆盖模式。通过在setContentView() 之前调用requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 为单个Activity 启用它。或者通过将android:windowActionBarOverlay 设置为true 在主题中。

【讨论】:

  • 非常好,正是我需要的。
  • 在我的情况下,我还必须在 super.onCreate(savedInstanceState); 之前放置 requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
【解决方案2】:

为活动的父布局创建一个RelativeLayout,并将您的操作栏放在布局的顶部,这将覆盖在主要活动内容的顶部,如下例所示。

RelativeLayout 允许您定位元素,但也允许您通过从上到下的顺序来确定视图元素的 z-index 顺序,即哪些视图在其他视图的前面/后面。

<RelativeLayout
    android:id="@+id/parent_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/action_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="100dp">

    </LinearLayout>
    <LinearLayout
        android:id="@+id/main_activity_content_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </LinearLayout>
</RelativeLayout>

现在您可以隐藏/显示 action_bar_layout 并且它不会影响 main_activity_content_layout 中活动内容的位置(通过使用布局的 setVisibility() 方法)

【讨论】:

    【解决方案3】:

    对于类似 Google Play Store 的效果,试试...

    • 试试this Lollipop 中引入的新工具栏小部件(API 级别 21)
    • Android 早期版本中的this api 也支持这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多