繁体   English   中英

fitsSystemWindows不在FragmentPagerAdapter添加的片段中工作

[英]fitsSystemWindows not working in fragments added by FragmentPagerAdapter

我的应用程序正在使用FragmentPagerAdapter将片段添加到ViewPager。 问题是属性android:fitsSystemWindows="true"不起作用。 它不会向元素添加填充。

我的主要布局如下:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.TabLayout
        android:id="@+id/viewPagerTab"
        android:layout_width="0dp"
        android:layout_height="48dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:tabIndicatorColor="@android:color/transparent"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/viewPagerTab"/>
</android.support.constraint.ConstraintLayout>

我设置我的适配器并添加片段。

    MainPagerAdapter adapter = new MainPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new TestFragment(), "Test");
    adapter.addFragment(new GroupFragmentManager(), "Group");
    adapter.addFragment(new ProfileFragment(), "User");
    viewPager.setAdapter(adapter);

    viewPagerTab.setupWithViewPager(viewPager);

我的寻呼机看起来像这样:

private class MainPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public MainPagerAdapter(FragmentManager manager){
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title){
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }
}

ProfileFragment的布局只包含简单的测试内容。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Profile"
        android:fitsSystemWindows="true"/>
</LinearLayout>

但它仍然没有画出填充物。 我也设置了正确的款式。

<style name="Base.Theme.SnowLink" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">#FF4081</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

我搜索并测试了很多。 我认为android在加载的片段中存在一些问题,因为它在活动布局中有效。 我也使用数据绑定。

提前致谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM