我有一个隐藏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>
提前致谢。
答案 0 :(得分:30)
您可能正在寻找ActionBar
叠加模式。在Activity
之前调用requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
,为单个setContentView()
启用它。或者在主题中将android:windowActionBarOverlay
设置为true
。
答案 1 :(得分:0)
为活动的父布局创建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()方法)
答案 2 :(得分:0)