使用ViewPager&在状态栏后面进行控制fitsSystemWindow [英] Controls behind statusbar with ViewPager & fitsSystemWindow
问题描述
我有一个ViewPager
和Fragments
,其中包含全屏图像和一些底部对齐的控件.
I have a ViewPager
with Fragments
which contain fullscreen images and some bottom aligned controls.
我想确保控件不会通过fitsSystemWindow
消失在半透明导航栏的后面,但我似乎无法使其正常工作...
I want to make sure the controls do not disappear behind the translucent navigation bar with fitsSystemWindow
but I can't seem to make it work...
当我在不使用ViewPager
的情况下使用相同的xml时,它确实可以工作,因此ViewPager
似乎是"breaks".使用fitsSystemWindow
的能力.
It does work when I use the same xml without the ViewPager
so it seems the ViewPager
"breaks" the ability to use fitsSystemWindow
.
该活动的代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
这就是我要处理的片段:
This is what I have for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/initial_background_image"
android:scaleType="centerCrop"/>
<RelativeLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/button_icon_offset"
android:layout_marginBottom="@dimen/button_icon_offset"
android:layout_marginRight="@dimen/button_icon_offset"
android:fitsSystemWindows="true"
android:layout_gravity="bottom">
<Button
android:id="@+id/info_button"
style="@style/button_icon"
android:layout_gravity="left|bottom"
android:background="@drawable/button_info"
android:textAlignment="center"/>
<Button
android:id="@+id/share_button"
style="@style/button_icon"
android:layout_alignTop="@id/info_button"
android:layout_marginRight="@dimen/button_icon_divider"
android:layout_toLeftOf="@+id/like_button"
android:background="@drawable/button_share"/>
<Button
android:id="@+id/like_button"
style="@style/button_icon"
android:layout_alignParentRight="true"
android:background="@drawable/button_like"/>
</RelativeLayout>
</FrameLayout>
这就是我的最终结果...但是我希望按钮显示在导航栏的上方.
So this is what I end up with... But I want the buttons to appear above the navigation bar.
推荐答案
只需在您的style.xml中更改/删除此
Just change/remove this in your style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
...
</style>
是否仍然无法正常工作?而您使用的是
NestedScrollView
,然后添加"android:clipToPadding"
if still not working? and you're using
NestedScrollView
then add "android:clipToPadding"
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_green"
android:clipToPadding="false" <--add this
app:layout_behavior="@string/appbar_scrolling_view_behavior">
这篇关于使用ViewPager&在状态栏后面进行控制fitsSystemWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!